Building Resilient Systems: Handling Failures, Security and Monitoring

Building Resilient Systems: Handling Failures, Security and Monitoring

Explore how reliable systems handle failures through asynchronous communication, message queues, retries, circuit breakers, payment reconciliation, high availability, security, and observability.

Series: The Anatomy of Modern Systems: From Architecture to Scalability (5 articles)

  1. …
  2. 5
    Building Resilient Systems: Handling Failures, Security and Monitoring This article
A payment request may take seconds to process, but what happens when the bank takes thirty seconds to respond? What if the notification service is unavailable, the network connection drops, or the application server suddenly crashes?
These situations are part of running real-world applications. No system can guarantee that every component will always work as expected. What matters is how the system responds when something goes wrong.
This is where reliability engineering comes in. Queues help process requests without losing work, timeouts and retries handle temporary failures, and circuit breakers prevent failing services from overwhelming the rest of the application. Redundancy, security and monitoring add further layers of protection.
In this post, we'll explore how these mechanisms work together to build systems that can handle failures, protect data and remain available even when individual components break.

Asynchronous Communication: Processing Requests Without Blocking

In synchronous communication, the caller waits for the response. In asynchronous communication, it does not.
Synchronous Asynchronous
Service A → Service B Service A → Queue → Service B
Service A ← Response (A carries on immediately)
A message queue lets services communicate asynchronously: the sender puts a message in the queue and the receiver processes it later. In our app, the payment itself is synchronous, because Riya needs to know the result. The "payment received" SMS can be asynchronous.
Queues give us decoupling, protection from traffic spikes (messages wait their turn), and isolation from temporary failures: if notifications are down, messages simply wait.
In event-driven architecture, services produce and consume events. A successful payment emits one  PaymentCompleted  event, and any interested service reacts:



Failure Handling: Queues, Retries and Circuit Breakers

Tool
What it does
Example
Timeout
Stops waiting after a set time
Give up on the bank after 5 seconds
Retry with backoff
Tries again for temporary failures, waiting longer each time
Retry after 1s, 2s, 4s, then stop
Circuit breaker
Stops calling a service that keeps failing
After repeated bank errors, fail fast for a short period
Bulkhead
Isolates resources so one failure cannot use them all
Separate worker pools for payments and reports
Rate limiting
Caps incoming traffic
Reject excess requests with 429
Redundancy and failover
Extra components take over
Several app servers behind a load balancer
A cascading failure is when one failing component overloads or breaks the components that depend on it. Imagine the bank slows down, so payment threads pile up waiting, and soon the whole app is unresponsive. Timeouts, circuit breakers, bulkheads, queues and rate limiting all exist to stop that chain reaction.


Retries have a cost: they add latency and load, so cap the number of attempts and always back off.

Handling Uncertain Payments: Reconciliation and Transaction Recovery

Suppose the request to the bank times out. Did the payment happen? We do not know. The bank may have processed it and only the response was lost.
So we never blindly retry a payment, and we never assume it failed. Instead we check the status using the transaction or idempotency key from Post 3.
A payment moves through states:


Common situations and the right response:
Situation
Approach
Request takes too long
Timeout, then check status
Temporary failure
Controlled retry with idempotency key
Bank keeps failing
Circuit breaker
Duplicate request
Return the existing result
Systems disagree
Reconciliation
Riya is debited but the app says Failed. Treat this as an uncertain transaction, not a failure. Check the status, compare records across systems, and let reconciliation decide the final state.


Reconciliation compares transaction records between systems and flags mismatches. Never simply overwrite one status with the other.

High Availability and Disaster Recovery: Keeping Systems Running

Redundancy means extra components can take over when one fails: multiple app instances behind a load balancer, a database with a standby ready to take over, and tested backups. Disaster recovery is restoring systems and data after a major failure, using backups, replication, failover and regular recovery drills.
Two numbers define what "recovered" means:
  • RPO (Recovery Point Objective): the maximum acceptable data loss. An RPO of 15 minutes means losing up to 15 minutes of data is tolerable.
  • RTO (Recovery Time Objective): the maximum acceptable time to restore the service.
For money, RPO should be close to zero, which pushes us toward synchronous replication for the primary data.

Securing the System: Authentication, Authorization and Data Protection

Security starts with the network. A VPC is an isolated virtual network where we define subnets, routing and network rules. Resources go in different subnets depending on how exposed they should be:


A public subnet has a route to the internet. A private subnet does not directly expose its resources. The database should never be directly reachable from the internet.
Rules are enforced at two levels. A security group controls traffic for an individual resource (for example, only the app can reach the database port). A network ACL controls traffic at the subnet level. Network segmentation divides the network into sections and restricts communication between them.
On top of the network, a payment system should use:
  • TLS for data in transit and encryption for sensitive data at rest
  • Authentication and authorization on every request
  • Least privilege: each service gets only the access it needs
  • Secret management: passwords and keys live in a secrets store, never in code
  • Input validation on everything coming in
  • Audit logs recording who did what and when

Observability: Understanding What Happens Inside a System

You cannot fix what you cannot see.
  • Logs are detailed records of events: "TXN123 sent to bank".
  • Metrics are numbers over time: latency, error rate, CPU.
  • Alerts notify people when a condition needs attention.
For a payment system, watch:
Metric
Why it matters
Transaction success and failure rate
Overall health
API latency
Customer experience
Timeout rate
Early sign of a slow dependency
Error rate
Bugs and outages
Queue depth
Messages piling up
Duplicate attempts
Retry storms or client bugs
Database performance
A common bottleneck

The payment-system thread

We now put a queue between the payment service and the notification service, so a slow SMS provider never delays Riya's payment. Calls to the bank use timeouts, limited retries with the idempotency key, and a circuit breaker. An unknown result becomes PENDING and is settled by status checks and reconciliation.
The app runs on several instances in private subnets, the database is reachable only from the app, and logs, metrics and alerts tell us when something drifts.



Common mistakes

  • Retrying payments without idempotency. This is how double charges happen.
  • Treating a timeout as a failure. The payment may have succeeded.
  • Retrying immediately and forever. It turns a small outage into a bigger one.
  • No timeouts. One slow dependency can block every thread.
  • Database in a public subnet, or secrets hard-coded in the repository.
  • Alerting on nothing, or on everything. Alerts should signal action.
  • Never testing recovery. A backup you have not restored is a hope, not a plan.

Key takeaways

  • Queues and events decouple services and absorb spikes.
  • Timeouts, backoff retries and circuit breakers stop failures from spreading.
  • For payments, an unknown result is its own state: check the status, then reconcile.
  • Redundancy, backups, RPO and RTO define how we recover.
  • Put the database in a private network, and protect data in transit and at rest.
  • Logs, metrics and alerts turn surprises into signals.

The End of the Series

This brings us to the end of our system design series.
We started with a simple action: Riya tapping Pay ₹500 in an application backed by a single server and database. Across the series, we followed how that simple interaction evolves into a scalable and reliable system.
We explored how requests travel through networks and APIs, how databases store and protect transaction data, and how techniques such as load balancing, replication, caching, message queues, retries, circuit breakers, security and monitoring help systems handle real-world challenges.
Throughout this journey, one principle remained constant: there is no one-size-fits-all system design. Every architectural decision involves trade-offs, and the right choice depends on the system's requirements.
The next time you tap Pay, remember that a lot happens behind that single action. How does the system handle a timeout? What happens if a request is retried? How does it prevent duplicate payments? Which data must be immediately consistent, and which can tolerate a delay?
Understanding these questions is what makes system design more than just drawing architecture diagrams.
Thank you for following this series. I hope it has helped you understand how the systems we use every day are designed, built, scaled and made reliable.

Series: The Anatomy of Modern Systems: From Architecture to Scalability (5 articles)

  1. …
  2. 5
    Building Resilient Systems: Handling Failures, Security and Monitoring This article
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article