Lesson 4 of 4 High Availability Solutions

Designing Highly Available Cosmos DB and Storage

This lesson explains how replication settings behave during a failure.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe how Cosmos DB handles zone and regional failures.
  • Explain how applications use a read-access secondary.
  • Predict behaviour during a failure for a given configuration.

Azure Cosmos DB

Within a region, Cosmos DB keeps four replicas of each physical partition. Enabling availability zones places these replicas across zones, protecting the account from a datacenter failure at a small additional cost. Adding a second region adds a full replica set, and it raises the availability SLA for reads.

A multi-region account with a single write region can use service-managed failover, in which Cosmos DB promotes a secondary region if the write region fails, according to a priority list. With multi-region writes, there is no failover to perform, since other regions continue to accept writes, and such accounts reach the 99.999% availability SLA. Client SDKs should be configured with preferred regions, so that they route to the nearest healthy region.

Consistency affects resilience too. Strong consistency in a single write region gives an RPO of zero, whereas weaker levels can lose a small amount of recent data during a regional failure, in exchange for lower latency.

Sort into groups

What survives?

Exam skills 3.2.3

Decide what each Cosmos DB configuration survives.

Log in to try this activity Interactive activities are free with an account.

Azure Blob Storage and Azure Files

ZRS is the primary high-availability option: a zone failure does not interrupt reads or writes, and it needs no application change. GZRS adds a regional copy. With RA-GZRS or RA-GRS, applications can read from the secondary endpoint, which has the suffix -secondary, during a primary outage. The application must be built to use this endpoint, and it must tolerate slightly stale data.

For a regional outage, a customer-managed failover makes the secondary region writable. SDK retry policies can fall back to the secondary for reads automatically. For Azure Files, ZRS and geo-redundancy depend on the media tier: SSD shares support LRS and ZRS, whereas HDD shares support all four options.

Other storage services

Azure NetApp Files provides cross-zone and cross-region replication at volume level. Zone-redundant managed disks replicate Premium SSD and Standard SSD disks across three zones, so a disk can be reattached to a virtual machine in another zone. Azure Elastic SAN supports LRS and ZRS. Each service therefore needs a separate decision, and a design that has several storage types should address each of them.

Comparing availability behaviour

The following table recaps what happens when a failure occurs.

ConfigurationZone failureRegional failure
Cosmos DB, one region with zonesContinuesUnavailable
Cosmos DB, one write region with a read regionContinuesReads continue; writes after failover
Cosmos DB, multi-region writesContinuesContinues
Storage ZRSContinuesUnavailable
Storage RA-GZRSContinuesReads continue from the secondary; writes after failover

The following diagram compares how images and articles on a news site stay readable through a regional outage.

Keeping reads alive through a regional outage at the lowest cost. Images use RA-GRS or RA-GZRS, with the site or Azure Front Door falling back to the secondary endpoint. Articles use Cosmos DB with one write region and an extra read region, with preferred regions in the SDK. Publishing may stop, so multi-region writes are not justified.
The scenario is illustrative.

What the application must do

Replication settings do not by themselves make an application resilient. A client that targets a Cosmos DB account should list preferred regions, so that it reads from the nearest healthy region and fails over without a code change. Transient errors should be retried, and rate limiting responses should be honoured, with a client waiting for the suggested interval. Session tokens must be passed between application instances where they share a session, or the Session consistency guarantee will not hold across them.

Applications that use read-access storage need a defined behaviour. They should detect a failing primary, retry reads against the -secondary endpoint, and treat writes as unavailable, perhaps by queueing them or by entering a read-only mode. The Last Sync Time property of a storage account shows how far the secondary lags behind, which is useful when deciding whether to fail over. A design that never exercises this path often discovers its problems during the first real outage.

Choosing the correct level of protection

Not all data needs the same protection, and a design should tier its data by value. User-generated content that cannot be recreated might justify RA-GZRS, whereas a cache of rendered thumbnails could use LRS, as it can be regenerated. For Cosmos DB, a single region with availability zones may be enough for an internal application, whereas a global consumer service justifies several regions, with the cost of each additional region equal to a full replica of its throughput and storage.

The relevant comparison is always with the cost of failure. If an hour of outage costs little, a simple design with backups is appropriate. If it costs a great deal, the additional replication is easily justified. Stating this reasoning explicitly is good practice in real designs, and it is exactly the kind of judgement that scenario questions test through their qualifiers.

Scenario questions

Protection in proportion

Exam skills 3.2.3

Choose protection proportionate to the value of the data.

Log in to try this activity Interactive activities are free with an account.
Worked example

Reads during a regional outage

A news website serves images from Blob Storage and article metadata from Azure Cosmos DB. During a regional outage, readers must continue to see images and articles, although publishing can stop until the region recovers. Costs should be as low as this requirement allows. What should you recommend?

For images, RA-GRS or RA-GZRS gives a readable secondary, and the website or Azure Front Door falls back to the secondary endpoint. For Cosmos DB, one write region with an additional read region lets reads continue, and preferred regions in the SDK route traffic automatically.

Multi-region writes would keep publishing available, but the scenario accepts that publishing stops, so the extra cost is not justified. GRS without read access would require a failover before any image could be served. ZRS alone would not survive the regional outage.

Check yourself

What must an application do to benefit from RA-GRS during an outage?

Show answer

It must read from the secondary endpoint, and tolerate slightly stale data.

Exam Tips

Remember for the exam

  • Enable availability zones in Cosmos DB to spread replicas across datacenters.
  • Multi-region writes reach 99.999% and need no failover.
  • ZRS needs no application change; RA- secondaries need applications that use the secondary endpoint.
  • Each storage type needs its own availability decision.