Untitled Lesson
Skill Matrix
UNLOCK NODES BY LEARNING NEW TAGS.
Does implementing CQRS require using a separate database for reads and writes, or event sourcing?
💻 Code Challenge | +75 XP
Implement a PlaceOrderCommand/Handler pair that validates and persists through an Order aggregate, alongside a separate GetOrderSummaryQuery that runs a direct, denormalized read query bypassing the aggregate entirely.
A dashboard query performance issue is being blocked because "changing the read query might violate the Order aggregate's invariants." Reorder the steps to resolve this using CQRS thinking.
Task: Reorder the blocks in logical sequence to solve the problem.
A.D.A. Interface
Adaptive Didactic Assistant

Pascual Vila
Frontend Instructor // Code Syllabus
The Error //
Assuming CQRS requires a separate database and full event sourcing to be implemented at all
// Valid, simple CQRS — same database, separate code paths
// Write: await orderRepository.save(order); (through the aggregate)
// Read: await db.query("SELECT ..."); (direct, bypassing the aggregate)The Solution //
This misconception makes CQRS seem far more complex than it needs to be for most use cases. The simplest, valid form of CQRS just separates the code paths for commands and queries against the same database — a full separate read database updated via events is an advanced, optional extension, not a requirement.
The Error //
Routing a read-only query through the same aggregate/repository used for writes, unnecessarily constraining it
// Unnecessarily constrained: forced through the write-side aggregate
const order = await orderRepository.findById(id); // then manually reshape it
// Correct: a dedicated, freely-shaped read query
const summary = await db.query("SELECT ... FROM orders JOIN ...");The Solution //
Forcing a query to go through the write-side aggregate means it inherits that aggregate's structure and constraints even though it has no need to enforce any write-side invariant — this needlessly limits how the query can be shaped and optimized for its actual read use case.