How to Handle Errors in Production Without Waking Up at 3 AM

How to Handle Errors in Production Without Waking Up at 3 AM

Every team that ships software knows the sound: a phone buzzing at 3 AM because something broke in production. The fix is rarely a better pager. It is a system that sorts errors, alerts only when a human must act, and gives that human a clear next step. Good production error handling is mostly preparation done during the day, so the night stays quiet. This guide covers the pieces that matter most: sorting errors by impact, setting alert thresholds, writing runbooks, degrading gracefully, logging what matters, and sharing on-call fairly on a small team.

Sort First: How to Handle Errors in Production Without Panic

Not every error deserves the same response. A failed payment and a broken image thumbnail are both errors, but only one should wake anyone. The first step is to sort errors into a few clear buckets before you decide how to alert on them. Four buckets cover most cases, and a simple table keeps the whole team aligned on what each one means.

Severity What it means Response
Critical Users cannot pay, log in, or use a core feature Page someone now
High A feature is broken for some users, with a workaround Fix within the working day
Medium Something is wrong but users barely notice Fix in the next sprint
Low Cosmetic issues, noisy logs, dead links Fix when convenient

Tag every error with its severity at the point where you catch it, not later in a dashboard. The code that throws the error knows the context; a person triaging alerts at midnight does not. When you debug production issues without server access, that severity tag is often the first clue about where to look.

Review the buckets every month. Errors drift: a low-severity warning can grow into a real problem as traffic changes, and a critical alert that fires every week without action is a sign the classification is wrong. Keep the list short. If you need ten severity levels, the system is too clever to use under pressure.

Set Alert Thresholds That Respect Sleep

Most 3 AM pages come from thresholds set too low, not from real disasters. An alert that fires on a single failed request will wake someone for a blip that fixed itself. Error alerting thresholds should answer one question: does a human need to act right now, or can this wait until morning?

A practical starting point is to alert on rates, not single events. For example, page when the error rate passes 1% of requests for five minutes, or when a specific critical error appears more than ten times in ten minutes. Send a lower-priority message, not a page, for warning signs like a slow climb in response times or a queue growing longer than usual. The goal is a short list of alerts where every single one means action, not a stream of noise that teaches the team to ignore the pager.

Test the thresholds before you trust them. Replay a bad day from your logs and check which alerts would have fired. If the answer is forty pages, the thresholds are wrong. If the answer is zero during an outage you remember clearly, they are wrong in the other direction. Picking the right uptime monitoring tool helps, but no tool fixes thresholds that nobody tuned.

Write a Production Runbook People Can Follow at 3 AM

A runbook is a short set of steps for a known failure, written so a tired person can follow it without guessing. A good production runbook fits on one screen and starts with the symptom, not the system. “Checkout returns 500 errors” is a symptom. “Database connection pool exhausted” is a diagnosis, and it belongs later in the document.

Each runbook needs five things: how to confirm the problem, the first safe fix to try, how to check whether the fix worked, when to escalate, and how to roll back. Write the commands out in full. Nobody should have to remember a flag or a path at 3 AM. Link to the dashboards and logs the reader will need, and name the person or channel to contact if the steps do not work. The habit of testing code against bugs that only appear in production pairs well with runbooks, because both force you to think about failure before it happens.

Keep runbooks short and current. A runbook nobody updated after the last deploy is worse than no runbook, because it sends a tired engineer down a wrong path. After each incident, update the runbook that was used, or write one if it did not exist.

Degrade Gracefully Instead of Failing Loudly

Many outages are total only because the system insists on all or nothing. Graceful degradation means the app keeps working in a reduced form when a part fails. If the recommendation service is down, show the page without recommendations. If the search index is slow, fall back to a simpler search or a cached result. Users notice a missing widget far less than a blank page.

Build degradation in deliberately. For each dependency, decide what happens when it fails: use a cached value, skip the feature, or show a plain message. Set short timeouts so a slow dependency cannot hang the whole request. A three-second timeout on a non-critical call keeps the page fast; a thirty-second timeout turns one slow service into an outage for everyone. Circuit breakers help here: after a few failures, stop calling the broken service for a while and serve the fallback instead.

Test the degraded path the same way you test the normal one. A fallback that has never run in production is a guess, not a plan. Turn off a dependency in staging and watch what users would see.

Log What Matters and Nothing Else

Logs are the first place anyone looks during an incident, so they need to answer three questions fast: what happened, who was affected, and where in the code it happened. A useful log line includes a timestamp, a request or user identifier, the error type, and enough context to reproduce the problem. It does not include a full dump of every variable in scope.

Too many logs are as bad as too few. When every request writes ten lines, the real error hides in a flood of routine messages, and the storage bill grows for no benefit. Log errors and warnings with context, log key business events like payments and signups, and keep routine debug output behind a flag you can switch on when needed. A clear log management setup makes searching fast, but the discipline starts with what you choose to write.

Never log secrets. Passwords, tokens, API keys, and full credit card numbers have no place in logs, and they are hard to scrub once they spread to log storage, alerts, and backups.

Share the On-Call Load on a Small Team

On a team of three or four, on-call can feel like a permanent second job. The fix is a rotation with clear rules. One person is primary each week, and that person is the only one the pager calls. Everyone else sleeps. Keep rotations to a week so the load spreads evenly, and publish the schedule a month ahead so people can plan around it.

Protect the person on call. Give them a lighter daytime workload during their week, and make sure they are not also the person assigned the hardest feature work at the same time. After a bad night, give them the morning off without a meeting to defend it.

Finally, make sure a new hire can take a shift within a month. If only one person understands the system well enough to be on call, that is a knowledge gap, not a badge of honor. Pair new team members on incidents, let them shadow a shift, and keep the runbooks and dashboards good enough that the newest person can follow them. And when a deploy goes wrong, a practiced rollback with Docker tags is often the fastest way to stop the bleeding and get back to sleep.

The goal is not zero errors. Software will always break. The goal is a system where most errors fix themselves or wait until morning, where the few pages that do arrive come with a clear runbook, and where no single person carries the night alone. Start small: classify one service this week, tune one alert, write one runbook.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.