Coupang Machine Coding Round - They were expecting full running code to be completed in two hours
System Design Exercise: Product Bidding Platform (Simplified)
Objective
Design a basic simulation of a product bidding/auction system using object-oriented programming principles. The goal is to evaluate your ability to structure code in a modular, extensible, and logically organized way.
Scenario
You are tasked with designing a simplified bidding platform where:
- Users can register.
- Sellers can post products with a minimum price.
- Buyers can place bids on available products.
- Buyers can withdraw their bids.
- Sellers can view all bids in descending order.
- Sellers can accept the highest bid and complete the sale.
- Product listings are removed after a successful sale.
This is a simulation, not a real application. You are not expected to write actual APIs or integrate with databases.
Implementation Guidelines
Driver Class (Main Class)
- Acts as the entry point of the application.
- Simulates the frontend using print statements.
- No need to take input from the console.
- Should invoke methods from service classes to simulate flows.
Data Storage
- Use in-memory variables (e.g., arrays, lists, maps) to simulate a database.
- No need to use MySQL or any external storage.
Class Design Expectations
- Structure your code into POJOs, services, and repositories (if needed).
- Focus on modularity and separation of concerns.
- Avoid unnecessary complexity like interfaces or inheritance unless absolutely needed.
- Ensure that dependencies between classes are logical and minimal.
Functional Requirements
- User Registration
- Simulate adding users to the system. Done
- Users can act as both buyers and sellers. Done
- Post Product for Sale
- A seller can create a product listing with:
- Product name/description
- Minimum price
Product should be marked as "active" and available for bidding.
- Place Bid. -done
- A buyer can place a bid on an active product.
- The bid amount must be greater than or equal to the minimum price.
- Multiple buyers can bid on the same product.
- A buyer can update their bid (replace their previous bid with a new one).
- Validate that:
- The product exists and is active. —— Done
- The bid meets the minimum price requirement. — Done
- A seller cannot bid on their own product. — Done
- Withdraw Bid
- A buyer can remove their bid from a product.
- If no bid exists for that buyer-product combination, print an appropriate message.
- View Bids (Seller Only)
- The seller can view all bids for their product
- Bids should be displayed in descending order (highest to lowest). —————PENDING
- Display bidder information and bid amounts.
- Accept Bid and Complete Sale
- The seller can accept a bid (typically the highest one).
- Once accepted:
- Mark the product as "sold".
- Remove the product from active listings.
- Record the sale transaction (buyer, seller, final price).
- Optionally, notify other bidders that the product has been sold.
Evaluation Criteria
You will be evaluated on:
- Class Segregation: Are responsibilities clearly divided among classes?
- Modularity: Can the system be extended easily?
- Logical Dependencies: Are classes dependent on the right components?
- Code Readability: Is the code easy to follow?
- System Thinking: Does the solution simulate realistic behavior?
• Edge Case Handling: How well does the system handle invalid operations?
Bonus Functionalities (Optional)
- Allow sellers to set a reserve price (different from minimum bid).
- Implement automatic sale to highest bidder after a time period.
- Track purchase/sale history per user.
- Allow sellers to reject all bids and relist the product.
- Implement bid notifications (simulated via print statements).
- Support multiple simultaneous active listings per user.
- Add product categories or tags for filtering.
Example Corner Cases to Consider
Case 1: No Bids on a Product
- A seller tries to view bids on their product, but no one has bid yet.
- Expected behavior: Display an appropriate message indicating no bids have been placed.
Case 2: Bid Below Minimum Price
- A buyer tries to place a bid lower than the minimum price.
- Expected behavior: Reject the bid and notify the user of the minimum price requirement.
Case 3: Seller Bids on Own Product
- A seller attempts to bid on their own product.
- Expected behavior: Prevent the bid and display an error message.
Case 4: Bid on Non-existent or Sold Product
- A buyer tries to bid on a product that doesn't exist or has already been sold.
- Expected behavior: Reject the bid with an appropriate error message.
Case 5: Withdraw Non-existent Bid
- A buyer tries to withdraw a bid they never placed.
- Expected behavior: Display a message indicating no bid exists to withdraw.
Case 6: Accept Bid on Product with No Bids
- A seller tries to accept a bid when no bids have been placed.
- Expected behavior: Display an error message indicating there are no bids to accept.
Sample Flow Simulation
=== Product Bidding Platform ===
-
Register Users
- User1 (Seller)
- User2 (Buyer)
- User3 (Buyer)
-
User1 posts Product "Laptop" with minimum price: $500
-
User2 bids $550 on Laptop
-
User3 bids $600 on Laptop
-
User2 updates bid to $650 on Laptop
-
User1 views bids on Laptop:
- User2: 650 −User3:600
-
User3 withdraws their bid
-
User1 views updated bids:
- User2: $650
-
User1 accepts User2's bid
- Product "Laptop" sold to User2 for $650
- Listing removed from active products
-
User3 tries to bid on Laptop
- Error: Product no longer available
Suggested Class Structure (High-Level Hint)
Consider organizing your code with classes such as:
- User: Represents a user (can be buyer/seller)
- Product: Represents a product listing with details
- Bid: Represents a bid placed by a buyer on a product
- BiddingService: Handles core bidding logic
- ProductService: Manages product listings
- UserService: Manages user registration
- BiddingPlatformDriver: Main class to simulate the system
Remember: This is just a suggestion. Feel free to structure your classes as you see fit based on your design principles.