---
topic: system-design
author: Crashtech Editorial
published: Nov 15, 2026 · read: 6 min
---

Sharing Data Between Microservices: Shared Databases vs Synchronous APIs vs Event-Driven Messaging

A pragmatic guide to sharing data across microservices: shared databases, synchronous APIs, event-carried state transfer, CDC, and the Outbox pattern.

– –

The transition from monolithic applications to microservices architectures promises decoupled release velocity, localized scaling, and autonomous engineering teams. In a traditional monolith, data sharing is trivial: all application domains query a single, shared relational database. Any module can execute SQL joins across customer profiles, product catalogs, and financial ledgers within a single ACID transaction.

However, moving to microservices mandates service data ownership: every microservice encapsulates its own persistence layer. Outside callers cannot directly query or mutate internal database tables; all access must flow through explicit interfaces.

While encapsulation eliminates monolithic deployment locks, real-world business processes cross service boundaries. An Order Service cannot process checkouts without customer addresses, inventory reservations, and payment methods.

Engineering teams face a fundamental architectural dilemma: how do you share data across services without recreating the tight coupling, cascading failures, and distributed transaction bottlenecks that microservices were built to eliminate?

+-----------------------------------------------------------------------------------+
|                     DATA SHARING PATTERNS IN DISTRIBUTED SYSTEMS                  |
+-----------------------------------------------------------------------------------+

Pattern 1: Shared Database (Anti-Pattern)
[ Service A ] -----\
                    +-----> [ Single Shared Database ] (Schema Coupling, Single Blast Radius)
[ Service B ] -----/

Pattern 2: Synchronous API Calls (REST / gRPC)
[ Order Service ] ===(HTTP GET /customers/12)===> [ Customer Service ] ---> [ DB ]
                                                    (Temporal Coupling, Latency Cascades)

Pattern 3: Event-Carried State Transfer (ECST)
[ Customer Service ] ---> [ Kafka Topic ] ---> [ Order Service ] ---> [ Local DB Cache ]
                           (Async Events)      (Zero-Latency Local Reads, Eventual Consistency)

1. Pattern 1: The Shared Database (Anti-Pattern vs Pragmatic Reality)

The shared database pattern connects multiple independent microservices to the same relational database instance or schema.

Architectural Pathologies:

  1. Schema Governance Gridlock: If the Customer team alters a column name, modifies an index, or adds a non-null constraint, they cannot deploy without auditing every line of SQL across all other services in the organization.
  2. Bypassed Business Invariants: When Service B writes directly to Service A’s tables, it bypasses the validation logic, authorization checks, and lifecycle state machines implemented in Service A’s codebase.
  3. Database Connection Starvation: A sudden traffic burst or unindexed analytical query in the Analytics Service exhausts the database connection pool, starving the mission-critical Checkout Service of database connections.
  4. Blast Radius Collapse: If the primary database crashes, every microservice in the company fails simultaneously, eliminating fault isolation.
The Single Rule of Shared Databases:
If two services query the same SQL table in production, they are not two microservices.
They are a distributed monolith with network latency.

When Is It Permissible?

The only acceptable scenario for a shared database is the initial phase of a monolithic decomposition (the Strangler Fig pattern). Early-stage migrations may grant new services read-only database replicas while migration routes stabilize, with a strict timeline to transition to private stores.


2. Pattern 2: Synchronous API Delegation (REST and gRPC)

In this pattern, Service A queries Service B over synchronous HTTP/REST or gRPC protocols whenever it requires missing data attributes.

Incoming Checkout Request
           |
           v
   [ Order Service ]
           |
           |-- 1. HTTP GET /customers/101 (50ms) ----> [ Customer Service ]
           |-- 2. HTTP GET /inventory/item-9 (40ms) --> [ Inventory Service ]
           |-- 3. HTTP POST /payments/charge (120ms) -> [ Payment Service ]
           |
           v
Total Response Time = 50ms + 40ms + 120ms + Overhead >= 220ms

Advantages:

  • Strong Read Freshness: The caller always observes the most up-to-date data state directly from the authoritative source.
  • Simplicity: Employs familiar request-response paradigms without requiring message brokers or asynchronous event loop plumbing.
  • Zero Storage Duplication: Data exists in exactly one authoritative persistence store.

The Hidden Taxes of Synchronous Delegation:

  1. Temporal Coupling: Both services must be fully operational at the identical millisecond. If the Customer Service undergoes a rolling restart or hits a memory spike, the Order Service cannot process checkouts.
  2. Cascading Latency Accumulation: Total latency is the mathematical sum of all serial downstream hops plus network serialization:
Latency_total = Latency_Order + Latency_Customer + Latency_Inventory + Latency_Payment
  1. Compounded Availability Degradation: System availability is the product of individual service availabilities. If four dependent services each boast 99.9% uptime:
Availability_total = 0.999 * 0.999 * 0.999 * 0.999 = 0.996 (99.6% uptime)

An architecture with 99.6% uptime experiences over 35 hours of unscheduled downtime annually.


3. Pattern 3: Event-Carried State Transfer (ECST)

To break temporal coupling and eliminate network hop latency, mature distributed architectures utilize Event-Carried State Transfer (ECST) over durable message logs like Apache Kafka.

In ECST, whenever an entity changes in its authoritative service, that service broadcasts an event containing the full updated entity state. Subscribing services ingest these events and maintain denormalized, read-only projections inside their own local databases.

1. Customer Updates Address
[ Customer Service ] ---> Mutates DB ---> Emits Event to Kafka:
                                          "CustomerUpdated { id: 101, address: '123 Market St', tier: 'VIP' }"
                                                        |
                                                        v
                                          [ Kafka: "customer-events" ]
                                                        |
                                                        v
                                          [ Order Service Consumer ]
                                          Writes to local SQLite/Postgres table:
                                          customer_cache(id, address, tier)

2. Customer Later Checks Out
[ User ] ---> [ Order Service ] ---> Reads local table in 0.5ms (Zero network calls to Customer Service)

Architectural Benefits:

  • Zero-Latency Reads: When processing orders, the Order Service executes a local database join against its local customer_cache table. Zero remote network round trips are made.
  • Autonomous Resilience: If the Customer Service crashes or is taken offline for maintenance, the Order Service continues processing orders seamlessly using its local snapshot.
  • Scalability Decoupling: Downstream read spikes do not affect the upstream service’s primary transactional database.

The Trade-offs of ECST:

  • Eventual Consistency: There is a propagation lag (typically 10 to 200 milliseconds) between an update in the upstream service and the reflection in downstream local caches.
  • Storage Duplication: Common entities (such as users and products) are duplicated across multiple service databases, trading cheap disk storage for decoupled availability.
  • Schema Evolution Overhead: Event payloads become public contracts. Any breaking changes require strict Avro or Protobuf schema registry versioning.

4. Solving the Dual-Write Problem: The Transactional Outbox Pattern

When adopting event-driven data sharing, services must update their local database and publish an event to a message broker. Attempting to execute both operations naively in application code creates the notorious dual-write failure:

// Anti-pattern: Dual-Write Hazard
@Transactional
public void updateCustomer(Customer c) {
    customerRepository.save(c); // Step 1: Commits to Postgres
    kafkaProducer.send("customer-events", c); // Step 2: What if network drops here?
}

If the database commit succeeds but the message broker rejects the message (or the host crashes before the network call completes), downstream services never receive the update. The data states permanently diverge.

+-----------------------------------------------------------------------------------+
|                           TRANSACTIONAL OUTBOX PATTERN                            |
+-----------------------------------------------------------------------------------+

[ Application Service ]
       |
       | 1. Single Local ACID Transaction
       v
+---------------------------------------+
| Local PostgreSQL Database             |
|   |-- Table: "customers"              | (State Update)
|   \-- Table: "outbox_events"          | (Serialized Event Payload)
+---------------------------------------+
       |
       | 2. Read WAL / CDC (Debezium)
       v
[ Change Data Capture Engine ]
       |
       | 3. Guaranteed Delivery
       v
[ Apache Kafka Cluster ]

Implementation via Change Data Capture (CDC):

  1. Atomic Local Commit: The application writes the business record into the customers table and simultaneously appends a message into an outbox_events table inside the same local relational transaction.
  2. Transaction Log Tailing: A dedicated Change Data Capture engine (such as Debezium or AWS DMS) reads the database Write-Ahead Log (WAL) directly.
  3. Guaranteed Delivery: The CDC engine parses outbox insertions and publishes them to Kafka with at-least-once delivery guarantees, completely eliminating dual-write divergence.

5. Architectural Decision Matrix

Choosing the correct data sharing pattern requires evaluating data freshness requirements, latency sensitivity, and tolerance for operational complexity.

DimensionShared DatabaseSynchronous API (REST/gRPC)Event-Carried State Transfer
Coupling TypeSevere Schema & InfrastructureTemporal & Runtime AvailabilityLoosely Coupled Contract
Data FreshnessImmediate (ACID)Immediate (Strongly Consistent)Eventual (Millisecond lag)
Failure BehaviorPlatform-wide outageCascading request failuresAutonomous (Offline resilience)
Operational CostLow upfront, fatal at scaleModerate (Retries, Circuit Breakers)High (Brokers, CDC, Schema Registries)
Query PerformanceFast SQL joinsSlow (Sum of network hops)Ultra-fast (Local queries)
Recommended UseMonoliths / Early prototypesRare transactional mutationsHigh-throughput distributed reads

Practical Architectural Guidelines

  1. Default to Private Databases: Every microservice must own its persistence store. Never share database connections across service boundaries in production.
  2. Use Synchronous APIs for Direct Mutations: When a caller requires immediate validation and an atomic success/failure confirmation (such as credit card token authorization), use synchronous gRPC or REST paired with robust timeouts and circuit breakers.
  3. Use ECST for Read-Heavy Projections: When a service requires read-only foreign attributes to complete its local business logic, replicate that state asynchronously via event streams rather than querying across the network at runtime.
  4. Enforce Idempotency on Consumers: Because message brokers guarantee at-least-once delivery, event consumers must record processed message IDs to handle duplicate events gracefully.
  5. Protect Asynchronous Publishing with the Outbox Pattern: Always publish state change events using transactional outbox tables and log-based CDC to prevent data drift between local state and public event streams.
Advertisement

Frequently asked questions

Why is a shared database considered an anti-pattern in microservices?

When multiple services access a shared database schema, changes made by one team can break downstream services without warning. It couples deployments, prevents independent scaling, bypasses business logic validation, and creates a single point of failure that collapses the entire platform.

What is temporal coupling in synchronous service-to-service API calls?

Temporal coupling means Service A cannot complete its operation unless Service B is online, healthy, and responsive at that exact millisecond. If Service B slows down or suffers an outage, Service A exhausts its connection pools and fails, cascading downtime across the entire architecture.

What is Event-Carried State Transfer (ECST)?

ECST is an event-driven pattern where the publishing service includes full entity state attributes inside the event payload. Consumers maintain local read-only copies of that data in their own databases, allowing them to serve local queries without making network calls back to the source service.

How does the Transactional Outbox pattern solve the dual-write problem?

It writes both the business entity update and an outbox event record into the same local database within a single ACID transaction. An asynchronous CDC process (like Debezium) tails the database transaction log and publishes the outbox events to a message broker with guaranteed at-least-once delivery.

Sources & further reading

/* Comments */