- Initial Question:**
Explores whether to use transactional consistency (a "dinner aggregate" for reservations) or eventual consistency (reservation created in a "user aggregate" with validation after the fact) for enforcing constraints like dinner capacity.- Example use case: A dinner reservation system where a dinner's capacity shouldn't be exceeded.
-
Consistency Boundaries:
- Transactional (Strong Consistency): Enforces constraints immediately but might reject valid opportunities, e.g., rejecting a customer outright if full.
- Eventual Consistency: Allows compensatory actions like waitlists, offering discounts, or next available slots, improving user experience.
- Rule of Thumb: Keep consistency boundaries small, ideally one user or session per boundary.
-
User Experience Perspective:
- Users could see a "confirming reservation" page while backend processes validate capacity.
- Polling or Updates: Use polling or web sockets to update users on reservation status without relying on synchronous responses.
- Resilience: Redirect users to a permalink for tracking reservation state (e.g.,
/reservations/123
), allowing reloads without losing context.
-
Aggregate Design Insights:
- Aggregates enforce constraints and emit correct events (e.g., "reservation confirmed" or "waitlisted").
- Design aggregates around decision-making rather than purely around data relationships.
- A "Dinner" aggregate could manage reservations for a specific night, but reservations themselves might better fit within their own aggregate.
- Example framing: A "consistency boundary" exists wherever decisions require consistent knowledge (e.g., dinner capacity, reserved seats).
- Collaborative Domains:
- Restaurant tables: Aggregates might model decisions over a single night's reservations or a specific table's availability.
- Stadium seats: Decisions (e.g., reserving a seat) are localized to specific events or timeframes.
- Chess or Board Games: The sequence of moves determines game state; consistency boundaries revolve around a single game's timeline.
-
Consistency vs. Context:
- Consistency is tied to decision-making, not to the data model itself.
- State is situational to a decision and doesn't exist in isolation.
-
Granularity of Aggregates:
- Design aggregates to include only the state required to make the decisions they're responsible for.
- Use eventual consistency when real-time correctness isn't critical, reserving aggregates for decisions that must always be correct.
-
Business Context Drives Design:
- Stakeholders prioritize service-level objectives (e.g., speed of response) over technical consistency concerns.
- Questioner plans to explore repository locking mechanisms for handling methods shared across multiple application services.
This discussion was rich with insights into distributed systems design, focusing on user experience, aggregate modeling, and consistency trade-offs.