Design bookstore and chat messaging systems
DatabricksSoftware Engineer · OnsiteLast updated
This question tests the ability to design two distinct systems: a reliable transactional e-commerce inventory service and a low-latency real-time chat application, focusing on appropriate database choices and communication protocols.
System Design: Bookstore & Real-time Chat
You are asked to design two microservices for a large online bookstore platform: the Book Inventory service and the Customer Chat service.
Part 1: Book Inventory Service
Design a system to track millions of book titles, their authors, and current stock levels across multiple warehouses.
- Requirements: High consistency for stock decrements during checkout. Support for searching books by title or author.
- Scale: 10 million SKUs, 5,000 requests per second.
Part 2: Customer Chat Service
Design a service that allows customers to chat with support agents in real-time.
- Requirements: One-on-one messaging, delivery status indicators (sent/delivered/read), and message history retrieval.
- Scale: 100,000 concurrent active users.
Expectations
For both systems, provide:
- API Design: Define key endpoints (e.g.,
checkout_book,send_message). - Data Model: Choose appropriate database technologies (SQL vs. NoSQL) and schema designs.
- Architecture: Describe the high-level flow of requests, including load balancing, caching, and state management.
- Trade-offs: Explain how you handle system failures (e.g., what happens if a chat message is sent while a user is offline?).
Hints
Hint 1
For the inventory service, consider how ACID properties are essential for preventing overselling during checkout.
Hint 2
For the chat system, analyze why WebSockets or long-polling are preferred over standard HTTP request-response patterns for real-time delivery.
Hint 3
Consider utilizing different storage engines for static catalog data (like book titles) versus high-velocity transient data (like chat messages).
Follow-up questions
- How would you implement a 'global search' feature that allows users to find books across all warehouses with low latency?
- If the chat service experiences a sudden spike in traffic, how would you ensure that the message history retrieval does not crash the database?
- How would you handle eventual consistency if you moved parts of the inventory system to a multi-region distributed setup?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.