0
0
Microservicessystem_design~25 mins

Choreography vs orchestration in Microservices - Design Approaches Compared

Choose your learning style9 modes available
Design: Microservices Communication Coordination
Design focuses on comparing choreography and orchestration approaches for coordinating microservices workflows. Does not cover detailed implementation of each microservice business logic.
Functional Requirements
FR1: Coordinate multiple microservices to complete business workflows
FR2: Ensure services communicate reliably and in correct order
FR3: Support asynchronous and synchronous interactions
FR4: Handle failures gracefully and allow retries
FR5: Allow easy addition or removal of services without major rewrites
Non-Functional Requirements
NFR1: Support up to 1000 concurrent workflow executions
NFR2: API response latency p99 under 300ms for synchronous calls
NFR3: System availability 99.9% uptime
NFR4: Minimal coupling between services to allow independent deployment
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
API Gateway or Service Mesh for routing
Message Broker (e.g., Kafka, RabbitMQ) for event-driven communication
Workflow Orchestrator (e.g., Temporal, Camunda) for orchestration
Microservices emitting and consuming events
Monitoring and logging tools
Design Patterns
Event-driven choreography pattern
Centralized orchestration pattern
Saga pattern for distributed transactions
Publish-subscribe messaging
Circuit breaker for failure handling
Reference Architecture
          +---------------------+          
          |  Client / Frontend  |          
          +----------+----------+          
                     |                     
          +----------v----------+          
          |     API Gateway     |          
          +----------+----------+          
                     |                     
        +------------+------------+        
        |                         |        
+-------v-------+         +-------v-------+
| Orchestrator  |         | Message Broker|
| (Centralized) |         | (Event Bus)   |
+-------+-------+         +-------+-------+
        |                         |        
+-------v-------+         +-------v-------+
| Microservice1 |         | Microservice1 |
+---------------+         +---------------+
        |                         |        
+-------v-------+         +-------v-------+
| Microservice2 |         | Microservice2 |
+---------------+         +---------------+
        |                         |        
       ...                       ...       
Components
API Gateway
Nginx, Kong, or AWS API Gateway
Entry point for client requests, routes to services or orchestrator
Orchestrator
Temporal, Camunda, or AWS Step Functions
Central component controlling workflow steps and service calls
Message Broker
Kafka, RabbitMQ, or AWS SNS/SQS
Event bus enabling services to publish and subscribe to events
Microservices
Any language/framework (e.g., Spring Boot, Node.js)
Business logic units that perform tasks and communicate via events or orchestrator
Monitoring & Logging
Prometheus, Grafana, ELK Stack
Track system health, workflow progress, and failures
Request Flow
1. Client sends request to API Gateway.
2. In orchestration: API Gateway forwards request to Orchestrator.
3. Orchestrator calls Microservice1 synchronously or asynchronously.
4. Microservice1 completes task and returns result to Orchestrator.
5. Orchestrator calls next microservice(s) based on workflow logic.
6. Orchestrator returns final response to API Gateway, then to client.
7. In choreography: Microservice1 performs task and publishes event to Message Broker.
8. Microservice2 subscribes to event, performs its task, then publishes next event.
9. This event-driven chain continues until workflow completes.
10. Client may receive asynchronous notification or poll for status.
Database Schema
Entities: - WorkflowInstance: id, status, start_time, end_time - ServiceTask: id, workflow_instance_id (FK), service_name, status, input_data, output_data, start_time, end_time - Event: id, event_type, payload, timestamp Relationships: - One WorkflowInstance has many ServiceTasks - Events are linked to ServiceTasks by context or correlation id This schema supports tracking workflow progress and event history.
Scaling Discussion
Bottlenecks
Orchestrator becomes a single point of failure and bottleneck at high concurrency
Message Broker overload due to high event volume
Microservices overwhelmed by burst traffic
API Gateway limits throughput
Database contention for workflow state updates
Solutions
Scale Orchestrator horizontally or use distributed orchestrators
Partition Message Broker topics and use multiple brokers
Implement autoscaling for microservices based on load
Use API Gateway clustering and caching
Use optimized database indexing, sharding, or NoSQL for state storage
Interview Tips
Time: Spend 10 minutes understanding requirements and clarifying scope, 20 minutes designing and explaining both choreography and orchestration approaches, 10 minutes discussing scaling and trade-offs, 5 minutes for questions.
Explain difference between choreography (decentralized) and orchestration (centralized)
Discuss pros and cons of each approach in terms of control, complexity, and scalability
Describe components needed for each approach
Show understanding of failure handling and monitoring
Highlight how to scale and maintain system reliability