LinuxLVIII · Clustered Service ArchitectureExternal state
External state and databases - the stateful backend
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
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
| Property | SQL | NoSQL |
|---|---|---|
| Schema | Required | Flexible |
| Transactions | ACID | Eventually consistent (typical) |
| Query | SQL | API-specific |
| Scale | Vertical (mostly) | Horizontal (typical) |
| Best for | Complex queries, transactions | Simple 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
| Workload | Backend |
|---|---|
| Transactions | PostgreSQL with replication |
| Sessions | Redis with persistence |
| Configuration | etcd or Consul |
| Files / blobs | S3 or MinIO |
| Search | Elasticsearch |
| Time series | Prometheus or InfluxDB |
Knowledge check
Knowledge check · 3 questions
Q1. What is the typical pattern for state in a cluster?
Q2. SQL is always the right choice for cluster state.
Q3. Which of the following are valid state backends? Select all that apply.
Passing score: 75%. Answers are checked in this browser.