CQRS eventual consistency Flashcards

1
Q

What does CQRS stand for?

A

Command Query Responsibility Segregation – A pattern separating read (query) and write (command) models.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does CQRS differ from CRUD?

A

CRUD: Single model for Create, Read, Update, Delete.

CQRS: Separate models for Commands (writes) and Queries (reads).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the main benefit of CQRS?

A

Simplified models (optimized for reads vs. writes).

Independent scaling of read/write workloads.

Better alignment with complex domains or high-performance systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

When is CQRS not recommended?

A

For simple CRUD-based systems, as it adds unnecessary complexity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do the command and query models communicate in CQRS?

A

Same database (shared storage).

Separate databases (e.g., ReportingDatabase) with event-driven updates or messaging.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What architectural patterns pair well with CQRS?

A

Event Sourcing (stores state changes as events).

Event Collaboration (services communicate via events).

Domain-Driven Design (DDD) (especially Bounded Contexts).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is eventual consistency in CQRS?

A

The query model may lag behind the command model temporarily (due to async updates).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In CQRS, how can read models optimize performance?

A

EagerReadDerivation (pre-compute data).

MemoryImages (keep read models in memory).

ReportingDatabase (offload complex queries).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Should CQRS be applied to an entire system?

A

No – Only to specific Bounded Contexts (DDD) where the benefits outweigh complexity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s a ReportingDatabase, and how does it differ from CQRS?

A

ReportingDatabase: Offloads only complex queries (keeps main model for most operations).

CQRS: Fully separates read and write models.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What’s a key risk of using CQRS?

A

Added complexity (harder to maintain, requires skilled team, and can reduce productivity if misapplied).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What type of UI fits well with CQRS?

A

Task-based UI (e.g., “Cancel Order” vs. generic “Save” in CRUD).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the core principle of CQRS?

A

Separating read (query) and write (command) operations into distinct models for optimization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the key challenges in traditional CRUD architectures that CQRS addresses?

A

Data mismatch (different read/write representations).

Lock contention (parallel operations).

Performance issues (complex queries, high load).

Security challenges (overlapping permissions).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How does CQRS improve performance?

A

Independent scaling of read/write workloads.

Optimized schemas (denormalized reads, transactional writes).

Simpler queries (materialized views avoid joins).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the two approaches to implementing CQRS?

A

Single data store (separate logic for reads/writes).

Separate data stores (different databases, synchronized via events)

17
Q

What is eventual consistency in CQRS?

A

Read models may lag behind write models temporarily (async updates).

18
Q

When is CQRS most beneficial?

A

High read-to-write ratios.

Complex domains (e.g., DDD, task-based UIs).

Collaborative environments (minimizes merge conflicts).

19
Q

What is a key trade-off of CQRS?

A

Increased complexity (harder to design/maintain vs. CRUD).

20
Q

How does CQRS enhance security?

A

By isolating write permissions (commands) from read-only queries.

21
Q

What pattern is commonly combined with CQRS, and why?

A

Event Sourcing (stores state changes as events; simplifies read model generation).

22
Q

What is a materialized view in CQRS?

A

A precomputed snapshot of data (optimized for fast reads, avoids joins).

23
Q

When should you avoid CQRS?

A

For simple CRUD apps (overkill) or when strong consistency is critical.

24
Q

How does CQRS support scalability?

A

Horizontal scaling of read models.

Low-contention writes (fewer instances).

25
What is the role of messaging in CQRS?
Handles async command processing and event propagation (e.g., via queues).
26
What is idempotent message processing in CQRS?
Ensuring duplicate messages (e.g., retries) don’t corrupt data.
27
How does CQRS align with Domain-Driven Design (DDD)?
Commands map to business tasks (e.g., "Book room" vs. "Update status"). Bounded Contexts define CQRS boundaries.