| Users | Data Volume | Service Count | Complexity | Communication |
|---|---|---|---|---|
| 100 users | Small (MBs) | Few (1-3) | Low - simple domains | Direct calls, simple APIs |
| 10,000 users | Medium (GBs) | Several (5-10) | Moderate - multiple bounded contexts | REST/gRPC with retries |
| 1,000,000 users | Large (TBs) | Many (20+) | High - complex domain models | Event-driven, async messaging |
| 100,000,000 users | Very Large (PBs) | Hundreds | Very High - multiple teams/domains | Advanced messaging, CQRS, eventual consistency |
Domain-Driven Design (DDD) basics in Microservices - Scalability & System Analysis
Start learning this pattern below
Jump into concepts and practice - no test required
At small scale, the database becomes the first bottleneck because all domain data is stored centrally, causing contention and slow queries.
As users and services grow, the complexity of inter-service communication and data consistency across bounded contexts becomes the bottleneck.
At very large scale, network latency and message broker throughput limit system responsiveness.
- Database Scaling: Use database per bounded context to isolate data and reduce contention.
- Service Decomposition: Split monolith into microservices aligned with bounded contexts.
- Asynchronous Communication: Use event-driven messaging (Kafka, RabbitMQ) to decouple services.
- CQRS and Event Sourcing: Separate read/write models to optimize performance and scalability.
- API Gateways and Load Balancers: Manage traffic and provide single entry points.
- Cache Frequently Used Data: Use Redis or similar to reduce database load.
- Partitioning and Sharding: Distribute data across multiple databases by domain or customer.
Assuming 1 million users with 10 requests per second each:
- Total requests: 10 million requests per second (distributed across services)
- Database QPS per instance: 5,000 -> Need ~2,000 DB instances or sharding
- Message broker throughput: Kafka can handle ~1 million messages/sec per cluster -> multiple clusters needed
- Storage: TBs to PBs depending on domain data retention
- Network bandwidth: 1 Gbps per server -> horizontal scaling with load balancers
Start by explaining the concept of bounded contexts and how DDD helps manage complexity by aligning microservices with business domains.
Discuss how scaling affects data consistency and communication patterns.
Outline bottlenecks and propose concrete solutions like database per context, event-driven architecture, and CQRS.
Use real-life analogies like teams working on different parts of a product to explain bounded contexts.
Your database handles 1000 QPS. Traffic grows 10x. What do you do first?
Answer: Introduce read replicas and caching to reduce load, then consider splitting the database by bounded contexts to scale horizontally.
Practice
Solution
Step 1: Understand the goal of DDD
DDD focuses on modeling software based on the real business domain and its rules.Step 2: Compare options with DDD goals
Only aligning software with business needs matches DDD's main purpose.Final Answer:
To align software design closely with business needs -> Option AQuick Check:
DDD = Align software with business [OK]
- Confusing DDD with performance optimization
- Thinking DDD is about UI or network improvements
- Assuming DDD is only about coding style
Solution
Step 1: Define Bounded Context
It is a boundary that defines where a particular domain model is valid and consistent.Step 2: Match options to definition
Only 'a clear boundary within which a domain model applies' correctly describes a Bounded Context.Final Answer:
A clear boundary within which a domain model applies -> Option DQuick Check:
Bounded Context = domain model boundary [OK]
- Thinking it is a shared database table
- Confusing it with UI or network concepts
- Assuming it is a technical infrastructure term
A unique object with an identity that persists over time and changes state.Solution
Step 1: Understand the description
The object has a unique identity and can change state over time.Step 2: Match description to DDD concepts
Entities have unique identities and mutable state; value objects do not have identity.Final Answer:
Entity -> Option BQuick Check:
Unique identity + state = Entity [OK]
- Confusing Entity with Value Object
- Thinking Aggregate is a single object only
- Mixing Repository with domain objects
Solution
Step 1: Identify the problem
The domain model is large and mixes unrelated concepts, causing complexity.Step 2: Apply DDD principle
Bounded Contexts separate different domain areas to keep models clear and manageable.Final Answer:
Define clear Bounded Contexts to separate domains -> Option AQuick Check:
Separate domains with Bounded Contexts [OK]
- Trying to use one aggregate for everything
- Merging services instead of separating
- Removing entities incorrectly
Solution
Step 1: Understand consistency in DDD aggregates
Aggregates define consistency boundaries; transactions should not span multiple aggregates or services.Step 2: Choose best practice for microservices
Use eventual consistency and asynchronous communication between aggregates to maintain scalability and reliability.Final Answer:
Design aggregates as consistency boundaries and use eventual consistency between them -> Option CQuick Check:
Aggregates = consistency boundaries + eventual consistency [OK]
- Trying distributed transactions across services
- Using a shared database breaking microservice boundaries
- Ignoring aggregates and consistency rules
