DATABASE
    advanced

    CQRS Pattern

    Software Engineer path · lesson 59 of 99
    Client UI
    Command API
    POST /users
    Query API
    GET /users
    Write Database
    (Relational / PostgreSQL)
    Async Sync
    Read Database
    (NoSQL / Elasticsearch)

    Command in, query out

    Sequence

    Order how a write flows through a CQRS system until it can be read.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    5 pieces left to place

    Test your knowledge

    20 questions
    Question 1 of 20
    Score: 0

    In a typical CQRS architecture, how is the Read Database updated when a write occurs?

    The short version

    CQRS is like a restaurant where the kitchen (write path) focuses entirely on cooking complex meals quickly, while a separate display case (read path) shows the finished meals so customers can view options instantly without entering the kitchen.

    In more depth

    Command Query Responsibility Segregation (CQRS)

    An architectural pattern that separates the data mutation operations (Commands) from the data retrieval operations (Queries).

    The Problem

    In complex domains, the data model used for validating business logic and writing data is often highly normalized and complex. Reading that same data requires expensive SQL joins, slowing down performance.

    The CQRS Solution

    Command Path: Optimized for safe, transactionally consistent writes (e.g., PostgreSQL).
    Query Path: Optimized for fast, highly-available reads (e.g., Elasticsearch, materialized views).
    Synchronization: Changes to the Write DB are published as events to asynchronously update the Read DB.

    Interview Questions

    Amazon
    Microsoft
    Netflix
    Amazon
    Shopify
    eBay
    Stripe
    Microsoft
    Google
    Netflix
    Uber

    Love this visualization?

    Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.

    100% free • No credit card required