0
0
Microservicessystem_design~25 mins

Anti-patterns (distributed monolith, chatty services) in Microservices - System Design Exercise

Choose your learning style9 modes available
Design: Microservices Architecture with Anti-patterns
Focus on service design and communication patterns. Database design and UI are out of scope.
Functional Requirements
FR1: Design a microservices-based system for an e-commerce platform
FR2: Services should handle user management, product catalog, order processing, and payment
FR3: Each service should be independently deployable and scalable
FR4: Services must communicate to fulfill user requests
Non-Functional Requirements
NFR1: System should support 10,000 concurrent users
NFR2: API response time p99 under 300ms
NFR3: Availability target 99.9% uptime
NFR4: Avoid tight coupling between services
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
API Gateway
Service Registry and Discovery
Message Broker for asynchronous communication
Individual microservices with own databases
Load Balancer
Design Patterns
Service Mesh
Event-driven architecture
Circuit Breaker
Bulkhead pattern
API Gateway pattern
Reference Architecture
          +----------------+          +----------------+
          |  API Gateway   |          |  Service Mesh  |
          +-------+--------+          +-------+--------+
                  |                           |
    +-------------+-------------+-------------+-------------+
    |                           |                           |
+---v---+                   +---v---+                   +---v---+
| User  |                   | Order |                   | Product|
|Service|                   |Service|                   |Service |
+---+---+                   +---+---+                   +---+---+
    |                           |                           |
+---v---+                   +---v---+                   +---v---+
| User  |                   | Order |                   | Product|
| DB    |                   | DB    |                   | DB     |
+-------+                   +-------+                   +-------+

Note: Services communicate asynchronously via message broker to reduce chatty calls.
Components
API Gateway
Nginx or Kong
Single entry point for clients, routes requests to services
User Service
Spring Boot microservice
Handles user registration, authentication, profile management
Order Service
Node.js microservice
Manages order creation, updates, and status
Product Service
Go microservice
Manages product catalog and inventory
Message Broker
Apache Kafka or RabbitMQ
Enables asynchronous communication between services to reduce chatty calls
Service Mesh
Istio or Linkerd
Manages service-to-service communication, retries, and circuit breaking
Databases
PostgreSQL per service
Each service owns its own database to avoid tight coupling
Request Flow
1. Client sends request to API Gateway
2. API Gateway routes request to appropriate microservice
3. Microservice processes request using its own database
4. If data from another service is needed, microservice publishes event to message broker
5. Other services consume events asynchronously to update their state or trigger actions
6. Service Mesh manages communication reliability and security
7. API Gateway returns response to client
Database Schema
UserService: User(id PK, name, email, password_hash) OrderService: Order(id PK, user_id FK, product_id FK, quantity, status) ProductService: Product(id PK, name, description, price, stock_quantity) Each service owns its schema with no shared tables to avoid distributed monolith.
Scaling Discussion
Bottlenecks
Excessive synchronous calls between services causing high latency (chatty services)
Tight coupling due to shared databases leading to deployment and scaling issues (distributed monolith)
Single API Gateway becoming a bottleneck under high load
Message broker overload if event volume grows rapidly
Solutions
Adopt asynchronous communication with event-driven architecture to reduce chatty calls
Ensure each service owns its database and data model to avoid distributed monolith
Scale API Gateway horizontally with load balancers
Partition message broker topics and scale brokers horizontally
Use service mesh features like circuit breakers and retries to improve resilience
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying scope, 20 minutes designing architecture and explaining anti-patterns, 10 minutes discussing scaling and trade-offs, 5 minutes for questions
Explain the difference between a distributed monolith and a true microservices architecture
Highlight problems caused by chatty services and how asynchronous communication helps
Discuss importance of service autonomy and database ownership
Mention use of service mesh for communication reliability
Address scaling bottlenecks realistically with practical solutions