A distributed system may be able to handle millions of requests, but that is of little use if the whole platform stops working when a single server fails. Handling high traffic and surviving failures are two separate problems. The second one is called availability.
Availability is the share of time a system is up, reachable, and responding to users. A highly available system keeps working even when some of its parts fail: it isolates the problem and keeps serving requests. In this article we use a food delivery app as the running example: customers browse restaurants, place orders, pay, and get an SMS when the order is confirmed.
1. Understanding Availability
Suppose the food delivery app runs on one app server connected to one orders database. Everything works until the app server crashes. The database is still healthy, but nobody can place an order.
The app server is a single point of failure: one component whose failure stops the whole service. Availability is about removing such points so that users can keep using the app when a part of it breaks.
Availability is often confused with scalability and reliability. They answer different questions:
| Property | Question it answers | Food delivery example |
|---|---|---|
| Scalability | Can the system handle more load? | Serving 10x more orders during a festival sale |
| Availability | Can users reach and use the system right now? | Customers can still order when one server crashes |
| Reliability | Does the system give correct results over time? | Every bill and delivery fee is calculated correctly |
A system can be available but not reliable: the app stays online, but a bug adds the delivery fee twice. It can also be reliable but not available: every bill is correct, but the app is down for an hour every evening.
2. Calculating Availability and the "Nines"
Availability is calculated with this formula:
Availability = Uptime / (Uptime + Downtime)
For example, if the app is up for 364 days in a year and down for 1 day:
Availability = 364 / 365 = 99.73%
Measure each important operation separately
One number for the whole app can hide a real outage. Customers may still be able to browse restaurants while payment is completely broken. That is why teams measure availability per operation, over a stated time window:
| Operation | Availability this month | What users experienced |
|---|---|---|
| Browse restaurants | 99.99% | A few minutes of errors |
| Add to cart | 99.95% | About 20 minutes of errors |
| Pay and place order | 99.5% | About 3.6 hours of failed orders |
| Whole app (one number) | 99.8% | Hides the payment outage |
Placing an order is the operation the business depends on, and it has the worst number. A single average would have hidden that.
The nines of availability
Engineers describe availability targets in nines. Each extra nine cuts the allowed downtime by about ten times (figures below use a 365-day year):
| Availability | Downtime per year | Downtime per month | Downtime per week |
|---|---|---|---|
| 99% (two nines) | 3.65 days | 7.3 hours | 1.68 hours |
| 99.9% (three nines) | 8.76 hours | 43.8 minutes | 10.1 minutes |
| 99.99% (four nines) | 52.6 minutes | 4.38 minutes | 1.01 minutes |
| 99.999% (five nines) | 5.26 minutes | 26.3 seconds | 6.05 seconds |
At four nines, one incident that takes an hour to fix already uses up the whole year's downtime budget. So every extra nine costs more: more redundancy, more automation, and faster recovery.
| Target | What it usually needs |
|---|---|
| 99.9% | A second server, basic monitoring, someone who can respond within a few hours |
| 99.99% | Automatic failover, health checks, an on-call rotation, tested recovery steps |
| 99.999% | Redundancy at every layer, multiple locations, fully automated recovery |
Calculating availability in Java
The formula is easy to check in a few lines of code. The program below works out the 99.73% from the example above, then turns each target into a downtime budget in minutes. A small helper like this keeps everyone on the team talking about the same numbers.
Output
Up 364 days, down 1 day -> availability 99.73%
Allowed downtime in minutes
Target | per year | per month | per week
99% | 5256.00 | 438.00 | 100.80
99.9% | 525.60 | 43.80 | 10.08
99.99% | 52.56 | 4.38 | 1.01
99.999% | 5.26 | 0.44 | 0.10Look at how fast the budget shrinks. At 99.999% the whole month allows less than half a minute of downtime, which is less time than it takes an engineer to open a laptop and log in.
3. Improving Availability Through Redundancy
Components in series
Placing an order passes through an API gateway, the order service, and the database. All three must be up for the order to succeed. This is a series dependency.
If each component is 99.9% available and they fail independently, we multiply their availabilities:
Overall = 99.9% × 99.9% × 99.9% ≈ 99.7%
Every component we add lowers the total. Five components at 99.9% each give about 99.5%, which is roughly 44 hours of downtime a year, compared with under 9 hours for one component. In series, the whole is weaker than its weakest part.
Components in parallel
Now run two identical order servers behind a load balancer. Either one can handle the request, so they work in parallel and the pair fails only if both are down at the same time.
Each server is down 0.1% of the time (0.001). If their failures are independent:
Both down = 0.001 × 0.001 = 0.000001 (0.0001%)
Pair availability = 100% − 0.0001% = 99.9999%
That moves us from three nines to six nines for this layer. Two conditions must hold: the load balancer must send traffic only to the healthy server, and that server must have enough spare capacity to take all the load. The number also covers only the server pair, not the database or the rest of the path.
Series vs parallel
In series, the system fails when any one part fails, so the total is lower than each part. In parallel, the system fails only when all copies fail together, so the total is higher than each part.
Series and parallel in Java
Here are both rules as two small Java methods. series() multiplies the availabilities. parallel() multiplies the chances of every copy being down at once and subtracts that from 1. The last line puts the two order servers back between the gateway and the database.
Output
Setup Availability Down/year
One component 99.9000% 8.76 h
Gateway -> service -> database 99.7003% 26.25 h
Five components in series 99.5010% 43.71 h
Two servers in parallel 99.9999% 0.01 h
Gateway -> 2 servers -> database 99.8000% 17.52 hThe last line is the one to remember. Two order servers fixed their own layer, but the full path is still only 99.80%, because the gateway and the database are each still a single copy. Redundancy has to cover every component on the path, not only the one you looked at first.
4. Common Causes of System Failure
The parallel calculation assumes the two servers fail independently. In practice they often fail together, for reasons like these:
| Cause | Examples | Takes down both copies when |
|---|---|---|
| Hardware failures | Disk, memory, power supply, or network switch dies | Both servers share the same rack, power feed, or switch |
| Software bugs and resource exhaustion | Memory leak, deadlock, CPU spike, unhandled exception | Both servers run the same faulty release |
| Network issues | Packet loss, latency spikes, DNS failure, network partition | Both sit behind the same network path or DNS record |
| Human error | Wrong config value, bad deployment, deleted resource | The same change is applied to every server at once |
At large scale, hardware failure is routine: a fleet of thousands of machines loses disks and power supplies every week. So the design must assume any single machine can disappear at any time, and copies must be kept as independent as possible: different racks, staged deployments, and separate network paths.
Cascading failures
A failure in one place can spread. If one server crashes, its traffic moves to the others; if they had no spare capacity, they overload and crash too, and the chain reaction takes down the whole service. Sections 7 and 8 show how to stop this.
5. Redundancy and Standby Models
Redundancy means keeping more than one copy of a component. There are two main ways to run those copies.
A. Active-Passive
One copy (active) handles all traffic. The other (passive) stays ready as a standby. For the orders database, the primary accepts all writes and keeps copying its changes to the standby.
If the primary fails, the system performs a failover:
Having only one writer keeps data simple: there is never any doubt about which copy holds the latest order. The cost is the gap during failover. Detecting the failure, promoting the standby, and reconnecting take time, and some orders fail in that window.
Pros: one clear writer, simple to reason about, the standby uses fewer resources.
Cons: failover takes time, a standby that never serves real traffic may fail when it is finally needed, and if the old primary is still alive when the standby is promoted, both may accept writes (split-brain).
How quickly the standby can take over depends on how ready it is:
| Standby type | State before failover | Recovery time | Cost |
|---|---|---|---|
| Cold standby | Powered off; app and data must be set up first | Minutes to hours | Lowest |
| Warm standby | Running and configured, but must catch up and be promoted | Seconds to minutes | Medium |
| Hot standby | Running with data already in sync, ready to serve | Seconds | Highest |
A cold standby suits disaster recovery for non-critical systems. A hot standby is still passive: it does not serve users until it is promoted. Whichever you choose, test it under real production load; a standby that cannot handle the traffic is no help during an outage.
B. Active-Active
All copies serve traffic at the same time behind a load balancer. If one order server fails, the others are already running, so there is no failover delay.
This works only if any server can handle any request. So shared state such as the cart and login session must live outside the servers, in a shared store. Stateless app servers are a natural fit for active-active.
Pros: no failover delay, every copy is tested by real traffic, no hardware sits idle.
Cons: each server needs spare capacity to absorb a failed server's share, state must be shared, and active-active databases are hard because several writers must agree on every change.
Health checks and the load balancer
The load balancer calls a health endpoint on each server every few seconds. After several failed checks in a row, it stops sending traffic to that server. Detection is not instant, so a few requests can still fail in that window. A good health check confirms the server can really serve an order (for example, it can reach the database), not just that its process is running.
The Java code below shows the idea. The load balancer checks every server once a second, takes a server out of rotation after three failed checks in a row, and puts it back once it passes again. Requests are spread round robin over the servers that are still in rotation.
Output
second 1: #100 order-1 ok, #101 order-2 ok
-- order-2 crashes
second 2: #102 order-3 ok, #103 order-1 ok
second 3: #104 order-2 FAILED, #105 order-3 ok
[check] order-2 failed 3 checks, out of rotation
second 4: #106 order-1 ok, #107 order-3 ok
second 5: #108 order-1 ok, #109 order-3 ok
-- order-2 is restarted
[check] order-2 healthy again, back in rotation
second 6: #110 order-1 ok, #111 order-2 okOrder 104 failed because order-2 had already crashed but had not yet failed three checks. That is the detection window described above. Checking more often, or removing a server after fewer failures, shortens it, but healthy servers then get removed more often by mistake. In a Spring Boot service you rarely write the health endpoint yourself: Spring Boot Actuator provides /actuator/health, and it can include the database connection in its status.
The load balancer itself must be redundant too, or it becomes the new single point of failure. Cloud load balancers are redundant by design; in your own data center, two load balancers usually share a virtual IP so the standby can take over the address.
6. Geographic Redundancy: Availability Zones and Regions
If all copies sit in the same building, one power cut or network outage there takes them all down. Spreading copies across locations removes that shared risk.
| Level | What it is | Protects against | Latency between copies |
|---|---|---|---|
| Availability zones | Separate data centers in one region with independent power, cooling, and network | One data center going down | Low, a few milliseconds |
| Regions | Separate geographic areas, such as Mumbai and Singapore | Regional disasters and region-wide outages | Higher, tens of milliseconds or more |
| Multiple cloud providers | Different providers, such as AWS and Google Cloud | A provider-wide outage | Varies |
Distance brings a trade-off in how data is replicated:
| Replication | How it works | Data loss on failover | Effect on writes |
|---|---|---|---|
| Synchronous | A write succeeds only after the remote copy confirms it | None | Every write waits for the round trip |
| Asynchronous | A write is confirmed at once; the copy catches up later | The last few seconds of changes | No extra delay |
Synchronous replication works well between nearby zones. Across regions the delay is usually too high, so asynchronous replication and eventual consistency are common there. For most apps, running across two or more availability zones is a sensible default. Multi-region is worth its cost when a regional outage is unacceptable or users are spread across the world.
Note
Redundancy is not free. Every standby, replica, and extra location costs money and adds something to operate. Add it where the reduced downtime is worth the cost.
7. Handling Overload with Queues
Systems also go down because they are overloaded, not only because something broke. During a big sale, the SMS provider slows down. If every order waits for the SMS to be sent, every order slows down with it.
Instead, the order service saves the order, puts an SMS job in a durable queue, and replies to the customer at once. Background workers send the SMS later.
The queue keeps each job until a worker confirms it is done, so if a worker crashes, another worker retries the job and no SMS is lost. Placing an order no longer depends on the SMS provider being fast.
Here is the same flow in Java. OrderService only publishes a job and returns. A worker takes a job from the queue, and the job is gone only when the worker finishes it. When worker-1 crashes halfway, the job goes back to the queue and worker-2 sends that SMS on the second attempt.
Output
Order 201 saved, SMS queued, reply sent at once
Order 202 saved, SMS queued, reply sent at once
Order 203 saved, SMS queued, reply sent at once
Jobs waiting: 3
worker-1 sent SMS for order 201 (attempt 1)
worker-1 crashed on order 202, job back in queue
worker-2 sent SMS for order 202 (attempt 2)
worker-2 sent SMS for order 203 (attempt 1)
Jobs waiting: 0In production the queue would be a message broker such as Kafka, RabbitMQ or Amazon SQS, and the job goes back automatically when a worker does not acknowledge it in time. Inside a single Java application, a BlockingQueue with a pool of worker threads follows the same pattern. Because a job can be retried, the worker should be safe to run twice for the same order, for example by remembering which order IDs already got their SMS.
8. Containing Cascading Failures
Suppose the restaurant recommendation service becomes slow. Requests to it pile up, the order servers run out of threads and connections, and soon even checkout stops working. A problem in an optional feature has become a full outage. Three tools stop this spread:
| Protection | What it does | Food delivery example |
|---|---|---|
| Timeout | Gives up on a call after a fixed wait | Stop waiting for recommendations after 200 ms |
| Circuit breaker | Stops calling a dependency that keeps failing, then tests whether it has recovered | Skip recommendation calls while the service is down |
| Fallback | Returns a reduced but usable response | Show the menu without the "Recommended for you" row |
A circuit breaker sits in front of the dependency and moves between three states:
Closed: calls go through normally while they mostly succeed.
Open: after failures pass a threshold, calls fail immediately without waiting on the slow service.
HalfOpen: after a cooldown, a few test calls are allowed. If they succeed the breaker closes, otherwise it opens again.
The recommendation service is still down, but its failure stays contained. Customers can browse and order as usual.
The Java code below puts a timeout, a circuit breaker and a fallback together. A call that takes longer than 200 ms counts as a failure. After three failures the breaker opens and skips the call for 3 seconds, then lets one test call through.
Output
second 1 | CLOSED | menu only (timed out)
second 2 | CLOSED | menu only (timed out)
second 3 | OPEN | menu only (timed out)
second 4 | OPEN | menu only (call skipped)
second 5 | OPEN | menu only (call skipped)
second 6 | OPEN | menu only (timed out)
second 7 | OPEN | menu only (call skipped)
second 8 | OPEN | menu only (call skipped)
second 9 | CLOSED | menu + recommendations
second 10 | CLOSED | menu + recommendationsThe customer gets the menu every second; only the "Recommended for you" row is missing while the service is slow. At second 6 the test call failed, so the breaker opened again. At second 9 the service had recovered, the test call worked and the breaker closed. In real Java services you would normally use a library such as Resilience4j, which gives you circuit breakers, timeouts and fallbacks, instead of writing this class by hand. Java's HttpClient also lets you set a timeout on every request.
Summary
| Technique | Failure it handles | In the food delivery app |
|---|---|---|
| Measure per operation | One average hiding a real outage | Track ordering separately from browsing |
| Active-passive with failover | The primary database going down | Standby promoted to primary |
| Active-active behind a load balancer | An app server going down | Other order servers keep serving |
| Health checks | Traffic sent to a broken server | Unhealthy servers get no traffic |
| Multiple zones or regions | A whole data center or region going down | App runs in more than one zone |
| Durable queues | Overload from slow background work | SMS sent later by workers |
| Timeouts, circuit breakers, fallbacks | A slow dependency dragging everything down | Menu shown without recommendations |
Availability measures how much of the time users can reach and use the system; reliability measures whether it gives correct results.
Components in series lower availability; redundant components in parallel raise it, but only if their failures are independent.
Cold, warm, and hot standbys trade cost against recovery speed; active-active removes the failover gap but needs shared state and spare capacity.
Availability zones and regions protect against whole-location failures, with a trade-off between synchronous and asynchronous replication.
Queues, timeouts, circuit breakers, and fallbacks keep overload and slow dependencies from becoming full outages.