---
title: "One line of Python, and a 3× drop in p99"
description: "Removing an unconditional structured-log warning (plus four Prometheus-style metric increments) from a Python ad-decisioning service's hot path cut sustained p99 latency from ~48ms to ~18ms and CPU from 8–10 to 2–4, with pre- and post-deploy latency bands not overlapping at all."
url: "https://swe.quest/articles/one-line-of-python-and-a-3-drop-in-p99-14f9e1be4e26014c"
canonical: "https://developers.soundcloud.com/blog//one-line-of-python-and-a-3x-drop-in-p99"
source: "SoundCloud Backstage"
published: "2026-08-11"
difficulty: "medium"
kind: "Case study"
reading_minutes: 9
tags: ["performance","python","observability","ads"]
---

# One line of Python, and a 3× drop in p99

A post on [SoundCloud Backstage](https://swe.quest/sources/soundcloud.md), published 2026-08-11, 9 min read, Case study. Original: [https://developers.soundcloud.com/blog//one-line-of-python-and-a-3x-drop-in-p99](https://developers.soundcloud.com/blog//one-line-of-python-and-a-3x-drop-in-p99)

## Summary

Removing an unconditional structured-log warning (plus four Prometheus-style metric increments) from a Python ad-decisioning service's hot path cut sustained p99 latency from ~48ms to ~18ms and CPU from 8–10 to 2–4, with pre- and post-deploy latency bands not overlapping at all. The guard treated fixed-policy callers that intentionally send no posteriors as anomalies, so it fired on 100% of traffic; the cost was the synchronous serialise-and-write to stdout under the GIL, not string formatting, as the barely-moved memory graph showed. A 5ms trough reading right after deploy would have overstated the win as 10×, so let changes ride a full traffic cycle before quoting numbers, distinguish expected from unexpected absence, and treat always-firing signals as bugs.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Ads](https://swe.quest/tags/ads.md) (Domains)

## Prerequisites

- latency percentiles ([easy posts on Performance engineering](https://swe.quest/tags/performance.md?difficulty=easy))
- Python GIL ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- structured logging ([easy posts on Observability](https://swe.quest/tags/observability.md?difficulty=easy))

## Keywords

SoundCloud, structlog, GIL, p99 latency

## Related posts

- [Reducing our pager load](https://swe.quest/articles/reducing-our-pager-load-9bf7f4a021b251f9.md): incident.io · 2022-04-22 · Medium · 7 min read · Incidents & postmortems, Observability, Go, SRE
  incident.io pages on every Sentry error, and cut the resulting noise with four quick changes instead of switching to error-rate alerting.
- [Logs, Metrics, and Traces: What Does Each Signal Tell You?](https://swe.quest/articles/logs-metrics-and-traces-what-does-each-signal-tell-you-3a828a88ec5fbd9a.md): Railway · 2025-11-07 · Easy · 8 min read · Observability, Incidents & postmortems
  Logs, metrics and traces answer different questions: metrics show when behaviour changed, traces show where in the service graph a request slowed or failed, and logs explain why.
- [How we improved availability through iterative simplification](https://swe.quest/articles/how-we-improved-availability-through-iterative-simplification-1aa63e0def5687e6.md): GitHub Engineering · 2024-07-23 · Medium · 6 min read · Performance engineering, MySQL, Ruby, Observability, Deployment
  GitHub cut timeouts in its Rails monolith with small, measured changes found through Datadog metrics, Splunk logs and custom MySQL slow-query monitors.
- [The journey of building a comprehensive attribution platform](https://swe.quest/articles/the-journey-of-building-a-comprehensive-attribution-platform-5e6be9b52947e115.md): Grab Engineering · 2024-02-20 · Easy · 8 min read · Ads, Stream processing, Data pipelines, System design
  Grab's ads and promo attribution system evolved from a Kappa-architecture streaming engine to a Lambda architecture that pairs real-time stream processing with Spark batch jobs over S3.
- [Incident Report: November 25th, 2025](https://swe.quest/articles/incident-report-november-25th-2025-0f5ac3667ca5f9ba.md): Railway · 2025-11-25 · Medium · 3 min read · Incidents & postmortems, Resilience, Scheduling
  Slow GitHub API calls (about 4x normal p95 latency) during peak hours backed up Railway's Temporal-based task queue, causing workers to run out of memory and crash in a cascading thundering-herd pattern as surviving and newly started workers were overwhelmed by the backlog.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
