Reliability in system design is the probability that a system does the right thing, correctly and consistently, over a period of time, even when parts of it fail. Availability asks "Did the system answer?"; reliability asks "Was the answer right?" A booking site that loads instantly but charges a passenger twice is available, not reliable.
In this article we follow one example the whole way: a railway Tatkal booking platform. At 10 AM, lakhs of passengers try to book the same few seats in a few minutes. Payments time out, apps retry, and one wrong step can mean a debited account with no ticket. We will measure reliability, see why systems break, and then add the techniques that keep bookings correct, with runnable Java code (plus Python and C++) for each one.
1. What is Reliability in System Design?
A reliable system performs its intended function correctly, over time, under expected conditions. Each part of that sentence matters:
| Part | Meaning | Tatkal example |
|---|---|---|
| Correctly | The output is right, not just any output | One seat booked, one fare charged |
| Over time | Measured across days and months, not one request | Bookings stay correct all month, not just today |
| Expected conditions | Normal load plus the failures you plan for | The 10 AM rush and a slow payment gateway |
Reliability does not mean nothing ever fails. Servers crash, networks drop packets and dependencies slow down. A reliable design assumes these faults will happen and stops them from turning into wrong results for the user.
2. Availability vs Reliability (and Two Close Cousins)
These words are often mixed up in interviews. They answer different questions:
| Property | Question it answers | Tatkal example |
|---|---|---|
| Availability | Is the system responding? | The booking page loads and returns HTTP 200 |
| Reliability | Is the response correct? | The PNR shown is really saved, and paid once |
| Fault tolerance | Does it keep working when a part fails? | Bookings continue with one server down |
| Durability | Is saved data kept after a failure? | Confirmed tickets survive a database crash |
Responding is availability; responding correctly is reliability
The four are related but independent. A system can be highly available and still unreliable: picture a booking API with 99.99% uptime that, for a small share of requests, debits the passenger but never saves the ticket. You can also trade one for another by accident. Serving cached seat counts keeps the page up when the database is slow, but the counts may be wrong, which gives up correctness for uptime.
Why users care more about reliability
Passengers forgive a page that is down for a minute. They do not forgive money taken without a ticket. Wrong answers destroy trust faster than downtime.
3. How Do You Measure Reliability?
Four numbers describe how reliable a service is. Here is what they mean for the booking service:
| Metric | Formula | What it tells you |
|---|---|---|
| MTBF (Mean Time Between Failures) | Total up time / number of failures | How often things break; higher is better |
| MTTR (Mean Time To Recovery) | Total down time / number of failures | How fast you recover; lower is better |
| Error rate | Failed requests / total requests x 100 | How many requests fail outright |
| Data correctness | Correct responses / successful responses x 100 | How many "successes" were actually right |
MTTR is not just repair time. It covers the whole path from the failure to a verified fix:
MTTR covers detect, diagnose, repair and verify
MTBF and MTTR also give availability directly: availability = MTBF / (MTBF + MTTR). This is why cutting recovery time is often the cheapest way to improve: halving MTTR helps as much as doubling MTBF, and faster detection (good alerts) is usually easier than preventing every failure.
Reliability metrics in Java
The program below takes one month of incidents for the booking service and computes all four numbers, plus a fleet estimate: with many servers, even a long MTBF per machine means failures become a regular event.
Output
Incidents this month : 4
Total downtime : 120 min
MTBF : 179.5 hours
MTTR : 30.0 min
Availability : 99.722 %
Error rate : 0.024 %
Data correctness : 99.994 %
Fleet: 40 servers, MTBF 2000 h each
Expect a server failure every 50 h
Compare the error rate and data correctness lines: the error rate is only 0.024%, yet 300 responses said "success" with wrong data. Error rate alone would have hidden that. Data correctness is the metric teams most often forget to track.
| System type | Typical target error rate | Meaning |
|---|---|---|
| Payments, bookings | Below 0.01% | At most 1 in 10,000 requests fails |
| Most business apps | Below 0.1% | At most 1 in 1,000 requests fails |
| Feeds, recommendations | Below 1% | At most 1 in 100 requests fails |
4. Why Do Systems Become Unreliable?
Failures come from five main sources, and each needs a different defence:
| Source | What happens | Typical defence |
|---|---|---|
| Hardware | Disks, memory or network cards fail; at scale this happens daily | Redundancy and replication |
| Software bugs | Every request on a buggy path fails the same way, or silently returns wrong data | Tests, code review, gradual rollouts |
| Configuration | A wrong timeout, URL or feature flag breaks a working service | Config review, validation, quick rollback |
| Human error | A wrong command or untested deploy under pressure | Automation, runbooks, guard rails |
| Overload | One slow part makes others wait, retry and fail | Timeouts, backoff, circuit breakers, bulkheads |
Overload deserves special attention because it spreads. When the payment gateway slows down at 10 AM, booking threads wait longer, the thread pool fills, apps retry immediately, and the extra retries slow the gateway even more:
A cascading failure: each step makes the previous one worse
Most techniques in the rest of this article exist to break this loop.
5. The Booking Platform We Will Make Reliable
Here is the design we start from. Passengers reach two booking services through a load balancer; the services use a primary database with a standby copy, call an external payment gateway, and push SMS and email jobs to a queue.
Components of the Tatkal booking platform
The requirements for reliability are simple to state: a passenger must never pay without getting a ticket (or a refund), never pay twice for one ticket, and never lose a confirmed ticket. The next sections add one technique at a time to meet them.
6. Redundancy and Failover
The first rule is to never let one component carry the only copy of the work or the data. Run at least two booking services, and keep a standby database that receives every change from the primary.
Health checks remove a bad server; a standby database takes over if the primary dies
The load balancer calls a health endpoint every few seconds. In Spring Boot this is usually the Actuator endpoint /actuator/health, which can also check the database connection. After a few failed checks the server is taken out of rotation. If the primary database dies, the standby is promoted. Two things decide whether this really works: the standby must be up to date (synchronous replication for confirmed tickets), and failover must be tested regularly. An untested failover path gives a false sense of safety.
7. Timeouts and Retries with Exponential Backoff
Every call to another service needs a timeout. Without one, a slow payment gateway holds a booking thread forever. Once a call times out, retrying often helps, because many failures are short: a dropped packet, a restarting pod. But retrying immediately and forever is what caused the cascade in section 4.
The fix is exponential backoff with jitter: wait a little before the first retry, double the wait each time up to a cap, add some randomness so thousands of apps do not retry at the same instant, and stop after a fixed number of attempts.
Retry with backoff and jitter, and give up cleanly
Output
Gateway recovers after 3 failures:
attempt 1: timeout, wait 77 ms
attempt 2: timeout, wait 164 ms
attempt 3: timeout, wait 353 ms
attempt 4: OK
Gateway stays down:
attempt 1: timeout, wait 66 ms
attempt 2: timeout, wait 133 ms
attempt 3: timeout, wait 338 ms
attempt 4: timeout, wait 771 ms
gave up after 5 attempts
First retry of 4 clients (50-99 ms):
client 1 waits 70 ms
client 2 waits 97 ms
client 3 waits 74 ms
client 4 waits 51 ms
The waits grow (77, 164, 353 ms) instead of hammering the gateway, the second case gives up after five attempts instead of looping forever, and the four clients spread their first retry between 50 and 99 ms. In Java you rarely write this loop yourself: Resilience4j Retry or Spring Retry's @Retryable with a backoff policy does it. One warning: only retry operations that are safe to repeat. Retrying "charge the fare" is dangerous, which is exactly what the next technique solves.
8. Idempotency: Making Retries Safe
Suppose the booking request reaches the server, the ticket is created and the fare is charged, but the response is lost on a weak mobile network. The app sees a timeout and retries. Without protection, the passenger gets two tickets and two charges.
An operation is idempotent if doing it many times has the same effect as doing it once. The usual way is an idempotency key: the app generates a unique key per booking attempt and sends it with every retry. The server remembers which keys it has already processed and returns the saved result instead of booking again.
The idempotency key turns a retry into a lookup
Output
Book Tatkal ticket (key k-77)
new booking PNR4521 on 12723, Rs 1450
Response lost, app retries (key k-77)
key k-77 seen before -> return PNR4521
User taps Book again (key k-77)
key k-77 seen before -> return PNR4521
New trip, new key (k-78)
new booking PNR4522 on 12760, Rs 980
Bookings: 2, total charged: Rs 2430
Three requests with key k-77 produced one PNR and one charge. In a real Java service the key is stored in a database table with a unique constraint, inside the same @Transactional method that creates the booking, so two retries arriving at the same moment cannot both pass the check. Payment providers such as Razorpay and Stripe support idempotency keys for exactly this reason.
9. Circuit Breaker: Stop Calling a Failing Service
Retries help with short failures. When the payment gateway is down for minutes, retries just add load and keep passengers waiting for timeouts. A circuit breaker watches the calls and, after too many failures, stops calling for a while and fails fast instead.
Circuit breaker states: closed, open and half-open
| State | What happens | Moves to |
|---|---|---|
| Closed | Calls go through; failures are counted | Open after 3 failures in a row |
| Open | Calls fail immediately without touching the gateway | Half-open after 5 seconds |
| Half-open | One trial call is allowed | Closed if it works, Open if it fails |
Output
t=0 CLOSED payment OK
t=1 CLOSED failed (1)
t=2 CLOSED failed (2)
t=3 CLOSED failed (3) -> OPEN
t=5 OPEN fail fast, no call
t=8 HALF_OPEN trial failed -> OPEN
t=9 OPEN fail fast, no call
t=12 OPEN fail fast, no call
t=14 HALF_OPEN trial OK -> CLOSED
t=15 CLOSED payment OK
From t=5 to t=12 passengers get an instant "payment unavailable, please retry" message instead of waiting for timeouts, and the gateway gets time to recover. At t=8 the trial call fails, so the breaker opens again; at t=14 the trial works and normal traffic resumes. In Spring Boot, Resilience4j's @CircuitBreaker(name = "payment", fallbackMethod = "...") gives you this with configurable thresholds.
10. Bulkheads: Contain the Damage
Ships are divided into watertight compartments called bulkheads, so one leak does not sink the whole ship. Software does the same with resources. If ticket booking, PDF downloads and train search all share one thread pool, a stuck PDF service can use every thread and stop bookings, even though booking itself is healthy.
Each feature gets its own pool, so one stuck feature cannot starve the others
Output
One shared pool of 8 threads
PDF downloads : 8 stuck, 0 rejected
Bookings : 0 served, 5 rejected
Bulkhead: booking 6, PDF 2
PDF downloads : 2 stuck, 6 rejected
Bookings : 5 served, 0 rejected
With one shared pool, the stuck PDF requests took all eight threads and every booking was rejected. With separate pools, only extra PDF requests are rejected and all five bookings go through. In Java this means a separate ExecutorService (or Resilience4j Bulkhead) per dependency, separate database connection pools for critical and non-critical work, and in Kubernetes, separate deployments with their own CPU and memory limits.
11. Graceful Degradation
When a part fails, a reliable system switches off features in order of importance instead of showing an error page. For Tatkal, the core job is taking a correct booking; everything else is optional:
Degrade step by step and keep the core booking flow alive
| Level | What still works | What is switched off |
|---|---|---|
| Full service | Everything | Nothing |
| Partial | Search, seat map, booking, payment | Train and berth suggestions |
| Core | Booking by class, payment | Live seat map |
| Emergency | Request saved in a queue, confirmed later by SMS | Instant confirmation |
Feature flags make this practical: each optional feature checks a flag, and operators (or the circuit breaker's fallback method) can turn it off without a deploy. The important design decision is made in advance: which features are core, and what the user sees when each optional one is off.
12. Checking Data Correctness: Reconciliation
Even with all of the above, some bookings will end in an unclear state: the bank debited the money, but the booking service crashed before saving the ticket. Reliable systems do not hope this never happens; they check for it. A reconciliation job regularly compares two sources of truth, here the payment records and the ticket records, and fixes every mismatch.
Reconciliation finds and fixes mismatches between payments and tickets
Output
ORD-102: paid Rs 980, no ticket -> refund
ORD-104: ticket but no payment -> alert
Matched: 3, refunded: Rs 980, alerts: 1
Order ORD-102 was paid but has no ticket, so it is refunded automatically; ORD-104 has a ticket but no payment record, so it is held and a person checks it. In Java this is typically a scheduled job (Spring @Scheduled or Spring Batch) that reads the bank's settlement file and the bookings table. This is the step most articles skip, and it is what turns "usually correct" into "correct or fixed by morning".
13. Monitoring and Testing Reliability
You cannot keep a system reliable if you only find out about problems from angry passengers.
| Practice | What it means | In a Java stack |
|---|---|---|
| Metrics | Track error rate, latency, timeouts and breaker state per dependency | Micrometer with Prometheus and Grafana |
| Alerts | Page someone when an SLO is at risk, not on every blip | Alertmanager rules on error rate |
| SLOs and error budgets | Agree a target such as 99.95% successful bookings; the gap is the budget for risk | Dashboards per service |
| Gradual rollouts | Release to a small share of traffic first | Canary deployments, feature flags |
| Failure testing | Kill servers and slow dependencies on purpose before real failures do it | Chaos tools, Testcontainers in tests |
Failure testing matters most for the techniques in this article: a circuit breaker, failover or fallback that has never been triggered is a guess, not a guarantee.
14. Common Mistakes
Retrying without backoff or a limit. This turns a small slowdown into the cascade from section 4.
Retrying non-idempotent operations. Charging or booking again on retry creates duplicates; add an idempotency key first.
No timeouts on outgoing calls. The default for many HTTP clients is to wait a very long time, which ties up threads.
Tracking only uptime and error rate. Wrong data with a 200 status is invisible unless you measure correctness or reconcile.
One shared pool for everything. A slow non-critical feature can block the critical one.
Never testing failover. The standby that has never been promoted is the one that fails when you need it.
15. Interview Questions on Reliability
What is the difference between availability and reliability? Availability is whether the system responds; reliability is whether the response is correct over time. A system can be available but unreliable.
Why is reducing MTTR often better than increasing MTBF? Availability is MTBF / (MTBF + MTTR), and recovery speed (fast detection, quick rollback) is usually easier to improve than preventing every failure.
How do you make a payment API safe to retry? Require an idempotency key, store it with a unique constraint in the same transaction as the payment, and return the stored result for repeated keys.
When would you use a circuit breaker instead of retries? Retries handle short, random failures; a circuit breaker handles a dependency that keeps failing, by failing fast and giving it time to recover. Most systems use both.
How would you make sure no passenger pays without getting a ticket? Idempotent booking, a transaction around ticket creation, and a reconciliation job that refunds any payment without a ticket.
Summary
| Step | Technique | Problem it solves |
|---|---|---|
| 1 | Redundancy and failover | One server or database dying |
| 2 | Timeouts, retries, backoff and jitter | Short failures and slow dependencies |
| 3 | Idempotency keys | Duplicate bookings and charges on retry |
| 4 | Circuit breaker | Repeated calls to a dependency that is down |
| 5 | Bulkheads | One slow feature starving the others |
| 6 | Graceful degradation | Error pages when an optional part fails |
| 7 | Reconciliation | Payments and tickets that do not match |
| 8 | Monitoring and failure testing | Problems found only by users |
The booking platform with every reliability technique in place
Reliability means correct results over time, even when parts fail; availability only means the system responds.
Measure MTBF, MTTR, error rate and data correctness; availability = MTBF / (MTBF + MTTR).
Use timeouts plus retries with backoff and jitter, and make every retried operation idempotent.
Circuit breakers and bulkheads stop one failing dependency from taking down the rest.
Degrade gracefully, reconcile data regularly, and test your failure handling before production does it for you.
Previous topics: Availability and Scalability. Next: Latency vs Throughput vs Bandwidth.