SOLID & Design Patterns Interview Question #65
Does CQRS require separate databases?
Advanced Patterns, CQRS & Domain-Driven Design Fundamentals Mid-Level Intermediate
Quick Interview Answer
No. CQRS is fundamentally about separating command and query responsibilities. Both sides can use the same database while using different application models or handlers.
Detailed Explanation
No. CQRS is fundamentally about separating command and query responsibilities. Both sides can use the same database while using different application models or handlers.
Separate read and write stores are an advanced option when independent scaling, specialized read models, or asynchronous projections justify the operational complexity.
Code Example
// Simple CQRS can share one DbContext:
public class CreateOrderHandler
{
private readonly AppDbContext _db;
}
public class GetOrderHandler
{
private readonly AppDbContext _db;
}