Skip to main content
RunBook Academy

LinuxLVIII · Clustered Service ArchitectureExternal state

External state and databases - the stateful backend

Advanced⏱ ~10 minbash

What you'll learn

  • Use databases as the cluster state
  • Distinguish SQL and NoSQL for cluster state
  • Apply caching patterns
  • Choose the right state backend

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

For most cluster architectures, the state is kept in an external system: a database, a cache, or an object store. The application is stateless. This lesson covers the patterns.

Databases as cluster state

The standard pattern: keep state in a database, keep the application stateless.

Pros:

  • Database does the hard work (transactions, replication, backup).
  • Application is stateless; any instance handles any request.
  • Database is the single source of truth.

Cons:

  • Database is a dependency (and a single point of failure if not replicated).
  • Network latency for every request.

SQL vs NoSQL

PropertySQLNoSQL
SchemaRequiredFlexible
TransactionsACIDEventually consistent (typical)
QuerySQLAPI-specific
ScaleVertical (mostly)Horizontal (typical)
Best forComplex queries, transactionsSimple access, high throughput

For cluster state, the choice depends on the access pattern:

  • Transactions and complex queries: SQL (PostgreSQL, MySQL).
  • Simple key-value: NoSQL (etcd, Redis).
  • Document storage: NoSQL (MongoDB).
  • Graph: Neo4j.

Caching patterns

A cache reduces database load:

Application → Cache (Redis) → Database
   |              |              |
   read-through, write-through, write-behind
  • Read-through: cache reads, fetches from DB on miss.
  • Write-through: cache writes to DB and updates cache.
  • Write-behind: cache writes asynchronously to DB.
  • Cache-aside: application reads from cache, writes to DB and invalidates cache.

Cache invalidation is the hard part: ensure the cache reflects the DB state.

Object stores

For files, blobs, and large data:

  • S3: de facto standard.
  • MinIO: self-hosted S3-compatible.
  • Ceph RGW: distributed object store.

Object stores are highly available, replicated, and durable. Use them for backups, media, large files.

Distributed state stores

For cluster coordination:

  • etcd: distributed key-value, leader election, used by Kubernetes.
  • Consul: service discovery, KV store, health checks.
  • ZooKeeper: similar, used by older Hadoop.

These provide the state that cluster managers (like Pacemaker) need.

Choose the right state backend

WorkloadBackend
TransactionsPostgreSQL with replication
SessionsRedis with persistence
Configurationetcd or Consul
Files / blobsS3 or MinIO
SearchElasticsearch
Time seriesPrometheus or InfluxDB

Knowledge check

Knowledge check · 3 questions

  1. Q1. What is the typical pattern for state in a cluster?

  2. Q2. SQL is always the right choice for cluster state.

  3. Q3. Which of the following are valid state backends? Select all that apply.

Passing score: 75%. Answers are checked in this browser.