Opening: A Green Dashboard, Angry Users
At 8:40 p.m., someone posts on social media: "Haven't been able to pay for my subscription for 40 minutes." A few others reply with the same complaint.
The team opens the dashboard. CPU 35%. Memory fine. Instance count normal. The only alert configured, "CPU above 80%", never fired.
The problem turns out to be the payment gateway rejecting 30% of transactions because of an expired certificate on our side. The servers are healthy. The users are not.
This part is about observability: being able to answer "why is the system doing this?" from the outside, without adding code first. And about alerting on what users feel, not on what is easy to measure.
Warm-Up Quiz: Do You Still Remember?
Answer first. All correct? Jump to the Summary. Missed one? Let's refresh the material.
Question 1. Out of 1,000 requests, 97% finish in 40–80 ms and 3% take 1.5–2.5 seconds. Which number reveals that suffering 3%?
- A. The average
- B. p95
- C. p99
Show the answer to question 1
C: p99. I simulated it: the average was 118 ms and p95 was 79 ms, both looking healthy. Only p99 showed 2,179 ms. When only 3% are slow, even p95 does not reach them. Section 2 has the details.
Question 2. Which alert deserves to wake someone at 3 a.m.?
- A. CPU above 80% for 5 minutes
- B. 5% of checkout requests failing for 5 minutes
Show the answer to question 2
B. Good alerts are based on symptoms users feel: error rate, latency, or an SLO burning too fast. High CPU with no user impact is no reason to wake anyone. And the reverse is the opening story: CPU at 35% while payments fail.
Question 3. On Cloud Run, the app prints one JSON line to stdout: {"severity":"ERROR","message":"payment rejected"}. What happens in Cloud Logging?
- A. It is stored as plain text with no level
- B. It is stored as a structured log with severity ERROR
Show the answer to question 3
B. Cloud Run's built-in agent turns a single JSON line on stdout or stderr into a structured log. Special fields such as severity and message move to their proper place, and other fields can be filtered on directly.
Question 4. Which field lets all the logs from one request be grouped together in Cloud Logging?
- A.
logging.googleapis.com/trace - B.
requestCount
Show the answer to question 4
A. Its value is projects/PROJECT/traces/TRACE_ID, where TRACE_ID comes from the header Cloud Run sends (for example X-Cloud-Trace-Context). Logs with the same trace are grouped under their request log, and can be linked to Cloud Trace.
Question 5. Which one is not one of the four golden signals?
- A. Latency
- B. Errors
- C. Deploys per week
- D. Saturation
Show the answer to question 5
C. The four golden signals from Google's SRE book are latency, traffic, errors and saturation. Deploy count is a useful team metric, but not a service health signal.
What did you score? Let's take them apart.
1. Three Pillars and Their GCP Equivalents
Picture a doctor examining a patient:
- Metrics are vital signs: temperature, blood pressure, heart rate. Quick to read, they show whether something is wrong.
- Logs are the medical notes: what happened, when, and the details.
- Traces are a record of the patient's path through the hospital: from the emergency room to the lab, to radiology, to the ward. They show where the time went.
| Pillar | Answers | On GCP |
|---|---|---|
| Logs | What happened in this request? | Cloud Logging (structured JSON logs), Error Reporting |
| Metrics | How healthy is the system overall? | Cloud Monitoring: dashboards, alert policies, uptime checks |
| Traces | Where is a slow request slow? | Cloud Trace, with OpenTelemetry |
| Alerts and on-call | Who gets woken up, and when? | Alert policies → email, Slack or PagerDuty |
The good news: Cloud Run already sends a lot without being asked: a request log for every request, plus metrics for request count, latency, instance count, CPU and memory. Our job is to add application logs you can search, and the right alerts.
2. The Four Golden Signals
- Latency: how long requests take. Look at p50, p95, p99, not the average. Also separate the latency of successful and failed requests: fast errors can make the average look good.
- Traffic: requests per second. A sudden drop is as suspicious as a sudden rise.
- Errors: the percentage of 5xx, and business errors. A payment rejected by the gateway may be answered with a 200 by your API, but it is still a failure for the user.
- Saturation: how full things are. CPU, memory, database connections against their limit, instance count against
--max-instances.
Why the average lies
That is question 1. I generated 1,000 latencies: 97% fast (40–80 ms) and 3% slow because of a heavy query (1.5–2.5 seconds):
const latensi = Array.from({ length: 1000 }, (_, i) => (i % 100 < 97 ? 40 + Math.random() * 40 : 1500 + Math.random() * 1000));
const urut = [...latensi].sort((a, b) => a - b);
const p = (q) => urut[Math.ceil(q * urut.length) - 1];
const rata = latensi.reduce((a, b) => a + b, 0) / latensi.length;
console.log(`rata-rata ${rata.toFixed(0)} ms | p50 ${p(0.5).toFixed(0)} ms | p95 ${p(0.95).toFixed(0)} ms | p99 ${p(0.99).toFixed(0)} ms`);
rata-rata 118 ms | p50 61 ms | p95 79 ms | p99 2179 ms
(rata-rata = average.)
Click the diagram to see it full size.
An average of 118 ms looks reasonable. A p95 of 79 ms looks great. Yet 30 of every 1,000 requests wait more than two seconds. With millions of requests a day, that is tens of thousands of bad experiences. And the users hit most often are usually your most active ones, because they send the most requests.
3. Structured Logs You Can Follow
A free-text log such as Error: payment failed for INV-7 can be searched, but not filtered by field. A JSON log can.
const PROJECT = process.env.GOOGLE_CLOUD_PROJECT ?? 'proyek-contoh';
// One JSON line on stdout = one structured log entry in Cloud Logging.
function log(severity, message, fields = {}, req) {
const entry = { severity, message, ...fields };
const header = req?.headers['x-cloud-trace-context']; // format: TRACE_ID/SPAN_ID;o=1
if (header) entry['logging.googleapis.com/trace'] = `projects/${PROJECT}/traces/${header.split('/')[0]}`;
console.log(JSON.stringify(entry));
}
One failed checkout request produces three lines:
{"severity":"INFO","message":"checkout dimulai","pesananId":"INV-7","userId":"u-42","logging.googleapis.com/trace":"projects/proyek-contoh/traces/4bf92f3577b34da6a3ce929d0e0e4736"}
{"severity":"ERROR","message":"pembayaran ditolak gateway","pesananId":"INV-7","alasan":"insufficient_funds","logging.googleapis.com/trace":"projects/proyek-contoh/traces/4bf92f3577b34da6a3ce929d0e0e4736"}
{"severity":"INFO","message":"request selesai","path":"/bayar-gagal","status":402,"durasiMs":1,"logging.googleapis.com/trace":"projects/proyek-contoh/traces/4bf92f3577b34da6a3ce929d0e0e4736"}
(checkout dimulai = checkout started, pembayaran ditolak = payment rejected, alasan = reason, request selesai = request finished.) In Cloud Logging, those three lines are grouped under the same request log because they share a trace. And you can search with a query like:
resource.type="cloud_run_revision"
severity>=ERROR
jsonPayload.alasan="insufficient_funds"
From structured logs you can also create a log-based metric, for example "rejected payments per minute, grouped by alasan". That metric can be alerted on. The opening story would be caught within minutes.
To see where the time goes (the database? a third-party API? your own code?), add OpenTelemetry and send spans to Cloud Trace. Traces can continue into other services through the W3C traceparent header that OpenTelemetry uses.
One non-negotiable rule: do not log sensitive data. Passwords, tokens, card numbers and personal data must stay out of logs, because logs are read by more people and kept longer than the database.
4. Alerts Worth Waking Someone For
Three rules:
- Based on symptoms, not causes. Checkout error rate, p99 latency, a burning SLO. Not CPU, not memory.
- Actionable. Every alert has an owner and written first steps (a runbook). Alerts nobody acts on get ignored, and then the important ones get ignored too.
- Matched to urgency. Not every problem needs to wake someone. Some can be a ticket for tomorrow morning.
Alerting from an SLO: burn rate
In Part 4 we worked out the error budget: a 99.9% SLO over 30 days means about 43 minutes. Burn rate is how fast that budget is used up. A burn rate of 1 means the budget runs out exactly at the end of the 30 days. A burn rate of 14.4 means it runs out in about two days.
Google's SRE workbook gives a widely used starting point:
| Condition | Burn rate | Action |
|---|---|---|
| 2% of the budget burned in 1 hour | 14.4 | Page someone |
| 5% of the budget burned in 6 hours | 6 | Page someone |
| 10% of the budget burned in 3 days | 1 | Ticket |
Cloud Monitoring can create SLOs for Cloud Run services and burn-rate alerts straight from the console. The benefit: one small blip wakes no one, but a big outage and a slow, steady decline both get caught.
5. Observability Has a Cost Too
Logs are billed by volume. At the time of writing, Cloud Logging includes the first 50 GiB per project per month for free, then about $0.50 per GiB, with an extra charge for keeping logs longer than 30 days. Check the pricing page for current numbers.
What inflates the log bill is almost always the same:
- an error inside a loop that logs the same message thousands of times a minute,
DEBUGlevel logging left on in production,- logging the full request and response bodies.
The controls: set the log level through an environment variable, sample very frequent logs (for example only 1% of successful requests), and add exclusion filters in the Log Router for logs nobody ever reads. The same goes for third-party error trackers: an error repeating in a loop can burn through the quota and push up the bill overnight.
6. When Latency Suddenly Spikes: What to Check, in Order
This order deliberately starts with the most common cause and the fastest recovery:
- Was there a new deploy? If so, roll back first (Part 4), analyse later. Restoring users matters more than understanding the cause.
- Traces: where is the time going? The database, a third-party API, or your own code?
- Saturation: is the database connection pool full? Are instances stuck at
--max-instances? Lots of cold starts? - Dependencies: the status pages of the payment gateway, the email provider, or other third parties.
- After recovery: write a short blameless postmortem. Focus on "why did the system allow this to happen" and what changes so it does not happen again.
One habit that makes step 1 fast: every log includes K_REVISION (Part 1). You immediately know whether errors only come from the newest revision.
7. Measure Before You Claim
Observability also applies before any incident. Capacity numbers you give your team should come from measurement, not guesses. At CahTix, I could only quote p95 latencies of 43, 96 and 180 ms for 1,000, 2,500 and 5,000 real-time clients after load testing with k6 on a 2 vCPU machine while watching the metrics.
The same habit on GCP: run a load test against a tagged revision (Part 4), watch the four golden signals in Cloud Monitoring during the test, and note where saturation starts to rise.
Summary
- Observability: answering "why?" from the outside. Logs (Cloud Logging), metrics (Cloud Monitoring), traces (Cloud Trace + OpenTelemetry).
- The four golden signals: latency, traffic, errors, saturation.
- Watch p99, not the average. In the test: an average of 118 ms and a p95 of 79 ms looked healthy, p99 was 2,179 ms.
- Structured logs: one JSON line on
stdout, withseverityandlogging.googleapis.com/trace. Never log sensitive data. - Alert on symptoms and SLO burn rate (2% in 1 hour, 5% in 6 hours), not CPU.
- Log costs are controlled with levels, sampling and exclusion filters.
- When latency spikes: a deploy? → traces → saturation → dependencies → a blameless postmortem.
Closing & What's Next
The opening story would be caught within five minutes with one log-based metric for "rejected payments per minute" and one burn-rate alert, long before anyone posted about it.
We now have an architecture, a way to keep it up, and a way to know when something breaks. The final part answers the question that leaves people guessing most: what if there are tens of millions of users? We will do rough maths, use Little's Law, and see why compute is rarely the problem, while the database almost always is.
Grab your coffee, see you in the next part!

Written by Muhammad Fari Madyan
Senior Backend Engineer and co-founder of LampungDev. I write up what I build so others can learn from it.

