| Users | Changes in System |
|---|---|
| 100 users | Single instance per microservice; simple API gateway; database per service; low latency |
| 10,000 users | Multiple instances per microservice; load balancer added; database replicas for reads; caching introduced |
| 1,000,000 users | Microservices deployed across multiple regions; database sharding; asynchronous messaging; CDN for static content |
| 100,000,000 users | Global multi-cloud deployment; advanced service mesh; automated scaling; event-driven architecture; data partitioning and archiving |
First microservice architecture diagram in Microservices - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small to medium scale, the database becomes the first bottleneck. Each microservice often has its own database, but as user requests grow, the database can struggle to handle the increased query load and data volume. This causes slower responses and potential downtime.
- Horizontal scaling: Add more instances of microservices behind load balancers to handle more requests.
- Database replication: Use read replicas to distribute read queries and reduce load on the primary database.
- Caching: Introduce caches (like Redis) to store frequently accessed data and reduce database hits.
- Database sharding: Split large databases into smaller parts based on user or data type to improve performance.
- Asynchronous messaging: Use message queues to decouple services and handle spikes smoothly.
- CDN: Use Content Delivery Networks to serve static content closer to users, reducing latency and bandwidth.
- At 10,000 users, expect ~1000-5000 requests per second (RPS) depending on user activity.
- Each microservice instance can handle ~1000-5000 concurrent connections.
- Database replicas can handle ~5000-10,000 queries per second (QPS) each.
- Cache can handle ~100,000 operations per second.
- Network bandwidth: 1 Gbps (~125 MB/s) can support thousands of requests with small payloads.
- Storage needs grow with user data; plan for scalable storage solutions like cloud object storage.
When discussing microservice scalability, start by explaining the architecture basics. Then identify the first bottleneck (usually the database). Next, describe step-by-step how to scale each component: services, databases, caching, and network. Use real numbers to show understanding. Finally, mention monitoring and automation for smooth scaling.
Your database handles 1000 queries per second (QPS). Traffic grows 10x to 10,000 QPS. What do you do first and why?
Answer: Add read replicas to distribute the increased read load and reduce pressure on the primary database. This is the quickest way to scale database reads without major redesign.
Practice
Solution
Step 1: Understand the API Gateway function
The API Gateway acts as a single entry point that directs client requests to the appropriate microservice.Step 2: Compare other options
Storing data is done by individual services, not the gateway. The UI runs separately, and the gateway does not replace microservices.Final Answer:
It routes client requests to the correct microservice. -> Option BQuick Check:
API Gateway = Request Router [OK]
- Thinking API Gateway stores data
- Confusing API Gateway with UI component
- Assuming API Gateway replaces microservices
Solution
Step 1: Recall microservice data ownership principle
Each microservice should own and manage its own database to avoid tight coupling.Step 2: Evaluate options
Sharing one database or file breaks independence. Not using databases is unrealistic for data needs.Final Answer:
Each microservice has its own separate database. -> Option CQuick Check:
Microservice = Own Data Store [OK]
- Assuming all services share one database
- Thinking microservices don't need databases
- Using shared files for data storage
Client -> API Gateway -> Service A -> Service BWhat happens if Service B is down when Client sends a request?
Solution
Step 1: Trace request flow with Service B down
The client request goes through API Gateway to Service A, which calls Service B. If Service B is down, Service A cannot complete its task.Step 2: Understand failure impact
Without Service B responding, Service A returns an error back through the API Gateway to the client.Final Answer:
Service A will fail to complete the request and return an error to the client. -> Option DQuick Check:
Down service causes error response [OK]
- Assuming automatic retries by API Gateway
- Thinking Service A can handle request alone
- Believing API Gateway has backup routing
What is the main problem with this design?
Solution
Step 1: Identify service call relationships
API Gateway calls both Service A and Service B, and Service A calls Service B and Service B calls Service A, forming a loop.Step 2: Understand circular dependency issues
Circular dependencies cause tight coupling and can lead to failures or deadlocks.Final Answer:
It creates a circular dependency between services. -> Option AQuick Check:
Circular calls = Bad design [OK]
- Thinking API Gateway shouldn't call services
- Believing shared database fixes call loops
- Assuming call direction must be reversed
- User service manages user profiles
- Product service manages product info
- Order service creates orders and needs user and product data
Which architecture diagram best fits these requirements?
Solution
Step 1: Analyze service responsibilities
User and Product services manage their own data. Order service needs to create orders using data from both.Step 2: Check communication flow
Order service calling User and Product services internally keeps responsibilities clear and allows data ownership.Step 3: Evaluate options
Client -> API Gateway -> User Service, Product Service, Order Service; Order Service calls User and Product Services internally. matches this design. Others either merge services incorrectly or create wrong call flows.Final Answer:
Client -> API Gateway -> User Service, Product Service, Order Service; Order Service calls User and Product Services internally. -> Option AQuick Check:
Order service calls needed services [OK]
- Merging all logic into one service
- Placing order service inside API Gateway
- Incorrect service call directions
