How we set up disaster recovery for a stateless service on AKS? - Part 4
How we designed active-passive disaster recovery for JsReport across Azure regions, including replicated storage, failover and recovery trade-offs.
How we set up disaster recovery for a stateless service on AKS? - Part 4
In the previous article, we discussed how we deployed, scaled, monitored and secured JsReport on AKS with Helm. Once the service was running well in one region, the next question came from the business, what happens if the whole region goes down? In this article, we are going to see how we set up disaster recovery (DR) for JsReport in active-passive mode, with West Europe as the primary region and North Europe as the secondary region, and why a “mostly stateless” service still had its own challenges.
TL;DR Summary
- A stateless service is easy to scale, but not automatically easy to recover. The state simply lives somewhere else, in our case in Azure Blob Storage, Key Vault, the container registry and the configuration.
- We chose active-passive, West Europe as primary and North Europe as secondary. They are an Azure region pair and both are in the EU, which keeps the data within the EU.
- Keeping the templates and generated PDFs in sync across regions was the hardest part, not the containers.
- Infrastructure as Code made the secondary region possible, the same templates and pipelines create both regions.
- Recovery Time Objective (RTO) and Recovery Point Objective (RPO) must be agreed with the business first, because they decide the cost and the design.
- Failback is harder than failover, and a DR plan that is never tested is only a hope.
What is Disaster Recovery?
Disaster recovery is the set of policies, tools and procedures to restore a system after a major failure, like a regional outage. In simple terms, it is our answer to the question, “if this region disappears now, how do we continue serving our customers, and how fast?”
Two terms drive every DR decision,
- Recovery Time Objective (RTO) - How long the service can be down before it hurts the business.
- Recovery Point Objective (RPO) - How much data we can afford to lose, measured in time.
Lower RTO and RPO means higher cost and more complexity. So, it is important to agree on them with the business before drawing any diagram.
Active-Active vs Active-Passive
There are two common ways to set up DR across regions,
| Approach | Pros | Cons |
|---|---|---|
| Active-Active | + Both regions serve traffic + Near zero RTO + Capacity is always warm | − Higher cost − Data must be written and read consistently in both regions − More complex routing and testing |
| Active-Passive | + Simpler data flow, one region writes + Lower cost + Easier to reason about | − Failover takes time − The passive region can silently drift − Secondary capacity is not guaranteed unless it is running |
We chose active-passive. JsReport is not a customer facing website that must be up every second, and the templates and PDFs are written in one place. Active-active would have forced us to solve two-way synchronization of the blob contents, which was not worth the cost for this service.
The Setup
The following diagram depicts our DR setup.

Here is how it works,
- Primary region (West Europe) - It runs the AKS cluster, serves all the traffic and writes the templates and PDFs to blob storage.
- Secondary region (North Europe) - It keeps the data services ready, and the cluster is created from the same ARM templates and pipelines when we fail over. It doesn’t serve any traffic until then.
- Blob storage - The templates and PDFs are replicated from the primary region to the secondary region.
- Container images - The same images and Helm charts must be available in the secondary region, so the cluster there can start without depending on the primary region.
- Traffic routing - All requests go to the primary region. During failover, we switch the traffic to the secondary region. The switch is driven by health checks. We built a special DR health check endpoint, which checks all the parameters that matter to confirm a DR scenario, not just whether the pod is alive. A simple ping only tells us the web server is up, but JsReport can be up and still unable to serve a report. So, the endpoint confirms the dependencies as well, and only when it reports the primary region as unhealthy, the traffic is moved to the secondary region.
But It is Stateless, Right?
This was the first assumption we had to correct. JsReport pods are stateless, any pod can serve any request, and we can kill and recreate them at any time. So, we thought DR is just running the same Helm chart in another region. It is not.
The pods are stateless because the state lives somewhere else. When we listed what a JsReport pod needs to serve a request, the list was longer than we expected,
- The templates, stored in blob storage.
- The generated PDFs, stored in blob storage and referenced by other applications.
- The secrets, stored in Key Vault.
- The container images and Helm charts, stored in the container registry.
- The configuration, like connection strings, URLs and feature settings, per environment.
- The network setup, like the static IP address, DNS and the Cloudflare configuration.
Every item in this list has to exist and be correct in the secondary region, otherwise the “stateless” pods start and fail on the first request.
Challenges
Let us discuss the challenges we faced while implementing the active-passive mode.
Keeping the templates and PDFs in sync
This was the biggest one. Find below the options we looked at to keep the blob contents in sync between West Europe and North Europe,
- Geo-redundant storage (GRS / RA-GRS) - Azure replicates the storage account to the paired region automatically. It is the simplest option, but the replication is asynchronous and there is no SLA on how far the secondary is behind. With RA-GRS, the secondary is read-only and has a different endpoint, until we initiate the account failover. After an account failover, the account becomes locally redundant and we have to enable geo-replication again.
- Scheduled copy with AzCopy - A pipeline or job runs
azcopy syncfrom the primary account to a separate account in the secondary region. We control the account and the endpoint in each region, but the RPO is as good as the schedule, and we own the job and its monitoring. - Object replication - Azure was just introducing asynchronous replication of block blobs between two storage accounts at that time. It is a good fit for this exact problem, but it was too new for us to depend on.
- Writing to both regions from the application - It gives the best RPO, but it moves the DR logic into the application and creates new failure modes, like what happens when one write succeeds and the other fails.
To keep it simple, we chose the first option, geo-redundant storage. The geo-replication takes care of the failover, the content is already in North Europe when we need it. On top of it, we made a decision to copy the content on demand during a failback, whatever is available in the secondary region is copied back to the primary region. If the content is not accessible, we are still covered, the templates will be pushed again from the backup and the PDFs will be regenerated. The templates change rarely and the PDFs can always be generated again from the templates and data, so we didn’t need a more complex replication for this service.
Whichever option you choose, keep in mind the following,
- Asynchronous replication means some data can be lost during a disaster. The templates change rarely, so losing the last few minutes is acceptable. A PDF generated a minute before the outage may not be in the secondary region yet. Agree with the business whether the consumers can regenerate it.
- Deletes are replicated as well. Replication protects us from a regional outage, not from a wrong delete. Use soft delete or backups for that.
- The template changes must flow only from the primary to the secondary. If someone edits a template in the secondary region during a failover, it must flow back during the failback, otherwise it is lost.
Region specific URLs
Some consumers stored the full blob URL of the generated PDFs. A storage account in another region has a different URL, and with RA-GRS the secondary endpoint has a different host name as well. So, after a failover, the old links point to the region that is down. The learning is simple, don’t hand out region specific URLs to consumers. Return an identifier or a URL behind our own domain, and resolve it to the right region at the time of the request.
The secondary region drifts silently
A passive region doesn’t serve any traffic, so nobody notices when it is broken. An expired secret, an older image, a configuration value updated only in the primary, a Kubernetes version that is behind, all of these stay hidden until the day we need the secondary region. That is the worst day to find them.
Infrastructure as Code helped a lot here. The same ARM templates and the same Helm chart create both regions, and only the parameters are different. And also, the deployment pipeline keeps the images, charts, secrets and configuration of the secondary region up to date with every release, so when the cluster is created during a failover, it gets the same version as the primary.
Warm or cold standby
We had to decide how much of the secondary region runs all the time,
- Cold standby - Create the secondary infrastructure only when we need it, using the spin up pipeline from Part 2. It is the cheapest, but creating an AKS cluster and deploying everything takes time, and the RTO grows with it.
- Warm standby - Keep a small AKS cluster running in the secondary region with the minimum number of pods, and scale it up during the failover. It costs more, but the RTO is much shorter, and we can run health checks against it all the time.
Capacity in the secondary region is also not guaranteed. In fact, during the early months of the pandemic, Azure reported capacity constraints in some regions as the demand jumped. If the secondary region is cold, we are competing with everyone else for capacity during a regional outage. A warm standby holds at least some of that capacity for us.
We went mostly with the cold mode. The storage account with the replicated templates and PDFs, the container registry and the secrets are always available in North Europe, because that is the data and it can’t be created at the time of the disaster. But the AKS cluster itself is not running all the time. During a failover, we run the same spin up pipeline from Part 2 against North Europe, deploy the Helm chart and only then switch the traffic. It keeps the cost of the secondary region low, and we accepted the longer RTO and the capacity risk as the trade-off for this service. This is also where the trial and error in the IaC pipeline paid off, the pipeline was already proven, so creating the cluster during a failover was a known step and not an experiment.
Images and charts in the secondary region
If the container registry is only in West Europe and West Europe goes down, the cluster in North Europe can’t pull the images. Azure Container Registry supports geo-replication, but only in the Premium tier. The alternative is a second registry in the secondary region and the pipeline pushing to both. Either way, the secondary cluster must not depend on anything in the primary region.
Secrets and identities
Key Vault content is replicated to the paired region by Azure, but during a regional outage it becomes read-only and the failover is managed by Microsoft, not by us. We preferred to have the secrets available in the secondary region on our own terms, with the deployment pipeline keeping them in sync. The service principals are in Azure Active Directory, which is a global service, so the identities themselves work in both regions, but their access policies and role assignments must be set on the resources in both regions.
Failback is harder than failover
Everyone talks about failover, but nobody plans for failback. Once the primary region is back, we have to move the traffic back, and bring back any template or PDF written in the secondary region during the outage. In our case, this was the only place where the template and PDF sync became a real problem, as we will see in the DR drills below. If we used the storage account failover, the account now lives in the secondary region and is locally redundant, so we have to set up the geo-replication again before we are protected. Write down the failback steps as carefully as the failover steps.
Patching and upgrades in two regions
In Part 3, we saw that node patching and cluster upgrades caused an outage until we designed for them. With two regions, we have two clusters to patch and upgrade. Since our secondary cluster is mostly cold, the good part is that it is always created fresh with the current Kubernetes version and node image during a failover or a drill. The DR drill becomes the safe place to try a new version first. Create the secondary with the new version, check it, and only then upgrade the primary. Never patch both regions at the same time.
Testing the DR plan
A DR plan that has never been tested is only a hope. We had to plan the DR drills, fail over to North Europe, run the service from there, and fail back, with the people who will actually do it during a real incident. Every drill found something, a missing configuration, a step that was not in the runbook, or a step that took longer than we thought. As expected, the main issue the drills brought out was the template and PDF sync, but only during the failback. The failover itself was fine, the geo-replication had already kept the content in North Europe. The problem appeared on the way back. The geo-replication works in one direction, from the primary to the secondary, so the templates and PDFs created or changed in North Europe while it was serving the traffic don’t flow back to West Europe on their own. The drills were the place to practice the steps we had agreed for exactly this case, copy on demand whatever is available, push the templates again from the backup when the content is not accessible, and regenerate the PDFs that didn’t make it.
Learnings
Here are the key learnings from our DR journey,
- Stateless doesn’t mean stateless system. List every dependency of the service, the state simply lives somewhere else.
- Agree the RTO and RPO with the business first. They decide between active-active and active-passive, and between warm and cold standby.
- The data is the hard part, not the containers. Plan the blob synchronization, the data loss window and the deletes.
- Don’t hand out region specific URLs. Keep an abstraction in between.
- Use the same IaC and the same pipelines for both regions, otherwise the secondary region drifts silently.
- The secondary region must not depend on anything in the primary region, not the registry, not the secrets, not the configuration.
- Plan the failback as carefully as the failover.
- Test the DR plan regularly, and treat every finding as a gift.
Self-Reflection
As an architect, I had drawn many DR diagrams with two regions and an arrow in between. Implementing one for a service that I thought was “just stateless” was a humbling experience. The arrow between the regions is where all the real questions are, what exactly is replicated, how fast, in which direction, and what happens to the data that didn’t make it. The trial and error we went through in the IaC pipeline paid off here, because creating the second region was just another run of the same pipelines with different parameters. The rest, the data, the URLs, the failback and the drills, needed careful thinking and honest conversations with the business.
Wrap up
In this article, we have looked at what DR is, why we chose active-passive with West Europe and North Europe, why a stateless service still carries state, and the challenges of keeping the blob contents in sync, avoiding drift, choosing between warm and cold standby, failing back and testing the plan. This brings us to the end of this series. I really appreciate that you took the time to read this series and I hope it provided you some insights into what it really takes to run, and recover, an application on AKS.
Related Posts
How we deployed, scaled and monitored JsReport on AKS with Helm? - Part 3
How we deployed JsReport with Docker and Helm on AKS, then scaled, monitored, secured and operated the service.
How we spin up and tear down AKS with Infrastructure as Code? - Part 2
How we created and removed JsReport’s AKS infrastructure with ARM templates and Azure DevOps pipelines, including drift and permissions lessons.
What we learned from containerizing JsReport on AKS? - Part 1
Lessons from containerizing JsReport on AKS, including Docker, Helm, Azure infrastructure, pipelines, scaling and the disposable environment lifecycle.