Modes of Dataflow: Databases, Services, Messages

The three ways encoded data travels between processes (through a database, through service calls, through a message broker) and what each one demands from compatibility, coupling and failure handling.

Overview

Whenever one process sends data to another process that does not share its memory, the data is encoded into bytes and decoded on the other side. There are three common paths for those bytes: through a database, through service calls (REST or RPC), and through asynchronous messages via a broker. Each path puts different versions of code in contact with each other, so each one has its own compatibility rules, its own coupling and its own way of failing.

Three paths for the same data

The three paths differ in timing, in whether both sides must be up at once, and in who must stay compatible with whom.

  • Through a database: the reader may come much later, so both sides need not be up at once. Every code version ever must be compatible with every record ever stored. Typical tools are PostgreSQL, MySQL and object storage.
  • Through service calls: the caller waits for the answer, so both sides must be up at once. Clients and servers must be compatible during rollouts. Typical tools are REST over HTTP and gRPC.
  • Through messages: the receiver processes later, and the two sides need not be up at once because the broker buffers. Producers and consumers must be compatible for as long as messages are kept. Typical tools are Kafka, RabbitMQ and SQS.

Key concepts

  • Dataflow through a database
  • Synchronous service call
  • Asynchronous message passing
  • Message broker
  • Idempotent operation
  • Deadline
  • At-least-once delivery
  • Partial failure

Interview questions

  • When would you use Kafka instead of REST for service-to-service communication?
  • Why is it a problem for several microservices to share one database?
  • A client calls a payment service and the request times out. What should it do?
  • In each mode of dataflow, whose code must be compatible with whose?
  • How do you make a message consumer safe against duplicate deliveries?

Sign up free to read the full topic

More DDIA topics

Start free on Cariara · Coding problems · System design studio