Skip to main content
InterviewHubPRO
Section Overview
Q46

Question 46 of 50

Part 3: Advanced Architecture & Production Patterns (Senior / Lead)

92%
Domain-Driven Design (50 Qs)•Part 3: Advanced Architecture & Production Patterns (Senior / Lead)

CQRS and Event Sourcing in DDD: State reconstruction and projections.

senior LevelCode ExampleSystem Design

In Simple Words:

  • Event-Sourced Aggregate: Has zero internal update statements. State is reconstructed from history:
    typescript
    class BankAccount {
      replayEvents(history: DomainEvent[]): void {
        history.forEach(event => this.apply(event));
      }
      private apply(event: MoneyDeposited): void {
        this.balance += event.amount;
      }
    }
    
  • Read Model Projections: As events occur, background workers project them into specialized denormalized read stores (Elasticsearch for search, Redis for caching, PostgreSQL for reports).