0
0
Microservicessystem_design~10 mins

Aggregates and entities in Microservices - Scalability & System Analysis

Choose your learning style9 modes available
Scalability Analysis - Aggregates and entities
Growth Table: Aggregates and Entities in Microservices
Users / RequestsWhat Changes?
100 usersSingle instance per microservice; aggregates handle entity consistency locally; simple database transactions.
10,000 usersMultiple instances of microservices; aggregates partitioned by business domain; database connection pooling; caching introduced.
1,000,000 usersMicroservices scaled horizontally with load balancers; aggregates sharded by entity ID ranges; eventual consistency patterns; asynchronous messaging between services.
100,000,000 usersGlobal distribution of microservices; aggregates split further; CQRS and event sourcing used; cross-region replication; advanced caching and CDN for read-heavy data.
First Bottleneck

The database managing aggregates becomes the first bottleneck. Aggregates enforce consistency boundaries, so heavy write/read loads on entities cause contention and slow transactions.

Scaling Solutions
  • Horizontal Scaling: Add more microservice instances behind load balancers to distribute traffic.
  • Sharding Aggregates: Partition aggregates by entity ID or business domain to reduce contention.
  • Caching: Use in-memory caches for read-heavy entity data to reduce database load.
  • Eventual Consistency: Use asynchronous messaging and event sourcing to decouple aggregates and improve scalability.
  • Database Replication: Use read replicas to scale read queries.
  • CQRS Pattern: Separate read and write models to optimize performance.
Back-of-Envelope Cost Analysis
  • At 1M users, assuming 10 requests per user per minute = ~166,000 requests/sec.
  • Each microservice instance handles ~3,000 concurrent connections; need ~60 instances.
  • Database handles ~5,000 QPS; sharding needed to distribute load.
  • Storage depends on entity size; for 1M entities at 1KB each = ~1GB; grows with history if event sourcing used.
  • Network bandwidth must support request and event message traffic; estimate 1 Gbps or more.
Interview Tip

Start by explaining aggregates as consistency boundaries in microservices. Discuss how entities inside aggregates are managed. Then describe scaling challenges as user load grows. Finally, propose solutions like sharding, caching, and asynchronous communication, linking each to the bottleneck it solves.

Self Check

Your database handles 1000 QPS. Traffic grows 10x. What do you do first?

Answer: Introduce read replicas and caching to reduce load on the primary database. Also consider sharding aggregates to distribute write load.

Key Result
Aggregates enforce consistency but cause database bottlenecks as load grows; scaling requires partitioning aggregates, caching, and asynchronous patterns.