<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0" -->

---
title: How to Synchronize Read and Write Databases in a CQRS...
description: A real-world case study on implementing CQRS for a hotel booking search system, using PostgreSQL as the write database and MongoDB as a read-optimized store....
canonical: https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Synchronize Read and Write Databases in a CQRS Architecture | daily.dev
og:description: A real-world case study on implementing CQRS for a hotel booking search system, using PostgreSQL as the write database and MongoDB as a read-optimized store....
og:url: https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0
og:image: https://api.daily.dev/og/posts/56nFIMTO0.png
og:image:alt: How to Synchronize Read and Write Databases in a CQRS Architecture
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Synchronize Read and Write Databases in a CQRS Architecture

**[Sergio Lema](https://daily.dev/sources/sergiolema-dev)** · 4 min read · 37 upvotes · 1 comments

## Summary

A real-world case study on implementing CQRS for a hotel booking search system, using PostgreSQL as the write database and MongoDB as a read-optimized store. The core challenge covered is keeping the two in sync: asynchronous message-broker-based updates (Kafka, RabbitMQ, SQS, Pub/Sub) provide near-real-time sync without blocking reads, while nightly batch rebuilds from a PostgreSQL view correct any data drift and act as a fallback for stale search results.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://sergiolema.dev/2026/09/07/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture>

## Questions this post answers

### How do you keep a MongoDB read database in sync with a PostgreSQL write database in a CQRS architecture?

Use a two-tiered strategy: publish a message to a broker like Kafka, RabbitMQ, AWS SQS, or GCP Pub/Sub on every PostgreSQL write so MongoDB processes updates asynchronously when read load is low, then run a nightly scheduled batch rebuild of the full MongoDB dataset from a PostgreSQL view to correct any drift the async pipeline missed.

_daily.dev surfaces architecture write-ups like this for engineers weighing CQRS sync strategies._

### Why not update the read database synchronously on every write in a CQRS system?

Synchronous replication blocks read operations on the read store during writes, and if multiple writes happen together the performance benefit of having a dedicated read database disappears. A hotel availability search system built on MongoDB with heavy read traffic found this approach undermined the whole point of separating read and write stores.

_Developers debating read-store consistency trade-offs can find this kind of case study on daily.dev._

### What is a fallback for when an asynchronous read-database sync hasn't caught up yet?

Create a database view on the write store (for example a PostgreSQL view) that the search fallback can query directly with the user's criteria when the read store is stale, such as during the hours before a nightly batch rebuild completes. It returns results more slowly than the dedicated read store but avoids showing empty or missing search results.

_daily.dev helps engineers building resilient search systems track patterns like this fallback approach._

## Community discussion

Top comments from developers on daily.dev.

**@agustinbarrientos** · 0 upvotes

> I wouldn't trust row counts before that swap. One missing date and one duplicate can cancel each other out.

## Similar posts on daily.dev

- [Optimizing Search Performance with CQRS: Relational Writes and NoSQL Reads](https://daily.dev/posts/optimizing-search-performance-with-cqrs-relational-writes-and-nosql-reads-3zldezxon) · Sergio Lema · 9 upvotes · 0 comments
- [CQRS Design Pattern](https://daily.dev/posts/cqrs-design-pattern-qyxe3wyb7) · Debezium · 118 upvotes · 1 comments
- [CQRS in Java: Separating Reads and Writes Cleanly](https://daily.dev/posts/cqrs-in-java-separating-reads-and-writes-cleanly-2mdeyndjt) · Foojay.io · 0 upvotes · 0 comments
- [Real-Time Data Sync Isn't Unsolved. It's Just Unfashionable.](https://daily.dev/posts/real-time-data-sync-isn-t-unsolved-it-s-just-unfashionable--5xlnylcgh) · Event Store · 0 upvotes · 0 comments
- [QCon SF: Database-Backed Workflow Orchestration Challenges Traditional Architecture](https://daily.dev/posts/qcon-sf-database-backed-workflow-orchestration-challenges-traditional-architecture-slmsieila) · InfoQ · 1 upvotes · 0 comments

---

Tags: [#architecture](https://daily.dev/tags/architecture), [#mongodb](https://daily.dev/tags/mongodb), [#postgresql](https://daily.dev/tags/postgresql), [#system-design](https://daily.dev/tags/system-design)

[View this post on daily.dev](https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Synchronize Read and Write Databases in a CQRS Architecture","url":"https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0"},"datePublished":"2026-09-07T05:11:01.977Z","dateModified":"2026-11-01T18:47:53.145Z","description":"A real-world case study on implementing CQRS for a hotel booking search system, using PostgreSQL as the write database and MongoDB as a read-optimized store....","image":"https://i0.wp.com/sergiolema.dev/wp-content/uploads/2026/05/pexels-photo-5738091.jpeg?fit=800%2C1200\u0026ssl=1","thumbnailUrl":"https://i0.wp.com/sergiolema.dev/wp-content/uploads/2026/05/pexels-photo-5738091.jpeg?fit=800%2C1200\u0026ssl=1","isAccessibleForFree":true,"articleSection":"Sergio Lema","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Sergio Lema","logo":"https://media.daily.dev/image/upload/s--SxVeO2EZ--/f_auto,q_auto/v1774964060/logos/sergiolema-dev?_a=BAMAMiWQ0","url":"https://daily.dev/sources/sergiolema-dev"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":37},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"architecture,mongodb,postgresql,system-design","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Sergio Lema","item":"https://daily.dev/sources/sergiolema-dev"},{"@type":"ListItem","position":3,"name":"How to Synchronize Read and Write Databases in a CQRS Architecture"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0","comment":[{"@type":"Comment","text":"I wouldn’t trust row counts before that swap. One missing date and one duplicate can cancel each other out.","datePublished":"2026-09-09T12:04:17.031Z","url":"https://daily.dev/posts/56nFIMTO0#c-k6orXzN8M","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-synchronize-read-and-write-databases-in-a-cqrs-architecture-56nfimto0#faq","mainEntity":[{"@type":"Question","name":"How do you keep a MongoDB read database in sync with a PostgreSQL write database in a CQRS architecture?","acceptedAnswer":{"@type":"Answer","text":"Use a two-tiered strategy: publish a message to a broker like Kafka, RabbitMQ, AWS SQS, or GCP Pub/Sub on every PostgreSQL write so MongoDB processes updates asynchronously when read load is low, then run a nightly scheduled batch rebuild of the full MongoDB dataset from a PostgreSQL view to correct any drift the async pipeline missed. daily.dev surfaces architecture write-ups like this for engineers weighing CQRS sync strategies."}},{"@type":"Question","name":"Why not update the read database synchronously on every write in a CQRS system?","acceptedAnswer":{"@type":"Answer","text":"Synchronous replication blocks read operations on the read store during writes, and if multiple writes happen together the performance benefit of having a dedicated read database disappears. A hotel availability search system built on MongoDB with heavy read traffic found this approach undermined the whole point of separating read and write stores. Developers debating read-store consistency trade-offs can find this kind of case study on daily.dev."}},{"@type":"Question","name":"What is a fallback for when an asynchronous read-database sync hasn't caught up yet?","acceptedAnswer":{"@type":"Answer","text":"Create a database view on the write store (for example a PostgreSQL view) that the search fallback can query directly with the user's criteria when the read store is stale, such as during the hours before a nightly batch rebuild completes. It returns results more slowly than the dedicated read store but avoids showing empty or missing search results. daily.dev helps engineers building resilient search systems track patterns like this fallback approach."}}]}
```

