M6-S2 — The stateful backends: high availability and upkeep
Section titled “M6-S2 — The stateful backends: high availability and upkeep”| Module | M6 — Scale and keep the backends healthy |
| After this session you can | Specify Northwind’s production datastores so a single failure stops nothing, wire the release to them, and know what a failover looks like from the platform’s side. |
| Time | Facilitated: 27 min · On your own: 27 min |
| Before you start | M6-S1. From M1-S2: what each store holds; from M4-S3: backups. |
| Go deeper | Maintenance operations · Maintenance: Redis failover · Runbooks: Redis master demoted |
◆ Orientation (1 min) — Three single points of failure
Section titled “◆ Orientation (1 min) — Three single points of failure”Your lab runs one copy of each datastore, and you have seen in M3-S2 that losing Redis alone stops the whole API. In production each of the three must survive the loss of a node, and you need to know what the platform does while one fails over. The datastores themselves often belong to a database team; this session gives you what to ask them for, and how to wire the release to it.
▤ Concept (3 min) — Highly available datastores, from the platform’s side
Section titled “▤ Concept (3 min) — Highly available datastores, from the platform’s side”MongoDB
Section titled “MongoDB”Production MongoDB is a replica set of at least three members: one primary takes writes, the
secondaries copy it and one is elected if the primary fails. Give the release connection strings that
name the replica set (?replicaSet=…, with the members or a seed list), so clients follow an election
on their own. Use authentication and TLS, and put the credentials in the secrets file.
Upkeep, from your side:
- Indexes come from the platform’s migrations, not from you. Do not create or drop indexes by hand; when search lags, use the reindex runbook (M7).
- Storage grows with the records and, in a single-tenant release, with the logs and audit trail the platform never purges (M5-S2). Watch disk use and plan for it.
- Backups (M4-S3): consistent dumps or snapshots of every database of the release, with the field-encryption key, rehearsed.
Redis holds what the gateway routes by, the sign-in state, and the background job queues (M1-S2). It is a single point of failure for the whole API, so it needs high availability as much as MongoDB does. The chart supports Redis Sentinel:
redis: sentinel: enabled: true sentinels: - { host: redis-sentinel-0.db.northwind.example.com, port: 26379 } - { host: redis-sentinel-1.db.northwind.example.com, port: 26379 } - { host: redis-sentinel-2.db.northwind.example.com, port: 26379 } masterName: mymaster useTls: "true"with the Sentinel and Redis passwords in the secrets file. During a Sentinel failover the platform
follows the new master by itself: a write that hits the demoted node is refused and resent to the
new master for up to 10 seconds, and every connection checks every 15 seconds that it still talks to
the master. Expect a short burst of retries, one log warning per burst, and the metric
osos_redis_master_reconnects_total rising. Without Sentinel, a replaced Redis keeps its address,
and nothing can follow anything.
Three rules for Redis:
- Several releases may share one Redis: keys start with the release name. But services use different database numbers (the verification service uses 0, most others 1), so consolidating onto one database number breaks them.
- Never
FLUSHALLa Redis the platform uses: it wipes the routing lists, sessions and job queues of every release on it at once. - TLS: the platform’s backend services encrypt their Redis connections but do not verify the server’s
certificate;
redis.sslVerifygoverns the gateway only. Keep Redis on a private network.
RabbitMQ
Section titled “RabbitMQ”The chart creates the release’s virtual host with quorum queues by default: each queue is replicated across the cluster’s nodes, so run RabbitMQ as a three-node cluster. Messages are persistent and queues durable (M1-S2), so a node loss delays work but does not lose it.
The chart has two ways to create the virtual host: the management-API Job you have used, or a
RabbitMQ Cluster Operator resource (rabbitmq.clusterOperator.enabled, with cluster,
clusterNamespace and vhost set), which makes the chart create a RabbitMQ Vhost resource instead
of the Jobs. The operator mode renders since chart 1.10.48.
Upkeep: alert on dead-letter queue depth (M5-S1, M7), rotate the bus credentials through
rabbitmq.url in the secrets file (a change rolls the pods that read it), and keep RabbitMQ’s own
disk and memory alarms monitored: when RabbitMQ blocks publishers, saving records still works but
everything that follows waits.
⛏ Lab (16 min) — Northwind’s production datastore plan
Section titled “⛏ Lab (16 min) — Northwind’s production datastore plan”Goal. A written datastore specification for Northwind’s production release, its Redis Sentinel values proved by a render, and a Redis restart observed from the platform’s side.
-
Fill in this table in
inventory.mdfor Northwind (about 1,500 users, 99.5 % availability target, a nightly backup with 30 days of retention):Datastore Topology Credentials and TLS Backup What you monitor MongoDB Redis RabbitMQ -
Add the Sentinel block from the concept to your
nw-prod-values.yaml(from M3-S1), and putredis.passwordandredis.sentinel.passwordplaceholders in a copy of your secrets file. -
Render the production file and find how the gateway now reaches Redis:
helm template nw ./osos -n northwind -f nw-prod-values.yaml -f nw-secrets.yaml -f pack-values.yaml | grep -n "sentinel" | head. -
Back on the lab release, restart Redis while watching the platform: in one terminal
kubectl -n northwind get pods -w, in anotherkubectl -n datastores rollout restart deploy/redis. -
Note which release pods became not ready for a moment, and that they recovered without a restart.
Check.
- Every row of your table names a topology that survives one node failure.
- Credentials are in the secrets file, never in the values file.
- The render shows the Sentinel configuration reaching the gateway and the services.
- You observed release pods losing and regaining readiness during the Redis restart.
- Your monitoring column includes the dead-letter queues and Redis reconnects.
Pass condition. All five checks hold, and your table matches the model answer in substance.
If something goes wrong
| What you see | What to do |
|---|---|
| The render fails on the Sentinel block | sentinels is a list of objects with host and port; check the dashes. |
| No pod lost readiness in step 5 | The restart was quick, or the probes ran between checks. That is fine; look at kubectl -n northwind get events for readiness failures. |
| Pods restarted instead of recovering | Read their previous logs; a restart is not expected for a short Redis outage. |
Model answer
| Datastore | Topology | Credentials and TLS | Backup | What you monitor |
|---|---|---|---|---|
| MongoDB | Replica set of 3 members in different zones; release connection strings name the replica set | A user per release with access to its databases only; TLS on | Nightly consistent dump or snapshot, 30 days kept, restore rehearsed quarterly, with the field-encryption key | Primary elections, replication lag, disk use and growth, slow queries |
| Redis | Primary and 2 replicas with 3 Sentinels; redis.sentinel.enabled | Password; TLS on, private network | None needed (the platform rebuilds it) | Memory, Sentinel failovers, osos_redis_master_reconnects_total |
| RabbitMQ | 3-node cluster; quorum queues (chart default) | A user for the release’s virtual host; TLS on | None needed; durable queues survive node loss | Dead-letter queue depth, queues without consumers, memory and disk alarms |
The render shows a sentinel:// address in the gateway’s configuration and the Sentinel hosts in the
release’s Redis Secret. During the lab restart, release pods that check Redis in their readiness
(for example indexing and the combined pods) flip to not ready for a few seconds, then back, with no
restart.
◇ Worked scenario (1 min) — A failover at 11:20
Section titled “◇ Worked scenario (1 min) — A failover at 11:20”At 11:20 Northwind’s database team patches the Redis primary; Sentinel promotes a replica. For a few
seconds, 500 REDIS_ERROR answers appear in the gateway log, and the identity and indexing logs show
Redis node answered READONLY: it is no longer the master; reconnecting.
Decide: act now? Not yet. That is the platform following the new master. Wait ten seconds and
watch osos_redis_master_reconnects_total rise once per connection, then stop.
At 11:25 the errors are still there. Now act: ask Sentinel which master it names
(SENTINEL get-master-addr-by-name mymaster). It still names the old node: the Sentinel quorum did
not agree. The database team fixes the Sentinels; the platform follows on its own once Sentinel names
the right master. No restart of the release was needed, and none would have helped while Sentinel
pointed at the wrong node.
✓ Practice (5 min) — Check your understanding
Section titled “✓ Practice (5 min) — Check your understanding”A colleague wants to save money by running Redis as a single instance “because it is only a cache”. What is your answer?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
To clear a stuck cache entry, an engineer proposes running FLUSHALL on the shared Redis. What
happens if they do?
Check your answer
The correct answer is C. Open the explanation under each option to see why.
Search results lag, and a database administrator proposes adding a MongoDB index by hand on the largest collection. What do you advise?
Check your answer
The correct answer is B. Open the explanation under each option to see why.
One RabbitMQ node of a three-node cluster fails during the day. What do users notice?
Check your answer
The correct answer is A. Open the explanation under each option to see why.
↺ Recap (1 min) — After Module 6 you can
Section titled “↺ Recap (1 min) — After Module 6 you can”After this module you can scale the tier that is the bottleneck, enable autoscaling the way the chart accepts it, size the combined pods, and specify and wire highly available MongoDB, Redis and RabbitMQ, knowing what a failover looks like from the platform’s side.
Next. Module 7 puts everything together under pressure: from a symptom to the right runbook, and a drill of real incidents on your lab.