Video in progress
Every service has its own DB. How do you plan disaster recovery, especially the consistency of data between services?
I set an RPO/RTO for every service depending on its business importance, with point-in-time recovery as the basis. You can't restore all services to the same point, so after recovery you need reconciliation that finds and fixes the differences between them.
📖 Answer
In a monolith, one DB backup is a single consistent point. With microservices there are 30 DBs, and each one's backup was taken at a different time. If you restore the order DB to its 14:00 state and the payment DB to its 14:03 state: for the orders within those 3 minutes there are payments, but the orders themselves are missing.
This is how I plan it.
Classification. For every service:
- RPO (how much data you can lose): payments, nearly 0; recommendations, a day;
- RTO (how long it can stay down);
- whether the data can be rebuilt from another source (search indexes, caches, projections: yes, and you may not need to back them up at all).
The technical base. PITR (the PostgreSQL WAL archive), a copy in another region/account (immutable storage as protection against ransomware), enough retention for Kafka topics or a mirror to another cluster.
Restoring a consistent state. Two ways:
- Use Kafka as the history of truth: after restoring the DB to an older point, rewind the consumer offsets to that point and replay the events. For this, consumers must be idempotent and topic retention must be sufficient.
- Reconciliation jobs: compare the
orderandpaymentdata, find differences like "a payment exists, no order", and resolve them automatically or by hand. Such jobs are useful not only for DR but day to day too, since they find bugs as well.
Rehearsal. A backup that has never been restored isn't a backup. Once a quarter: restore one service's DB into a separate environment, measure the time, run reconciliation. The first rehearsal usually turns up funny but dangerous problems like "who has the password" and "the script is out of date".
And a runbook: in what order things are restored (first identity and config, then the core services), who decides, what the business is told.
Sign up to mark studied questions and save your progress.