Library / Case Studies
XCMetrics: All-in-One Tool for Tracking Xcode Build Metrics at Spotify
TL;DR We just open sourced — a tool for Apple’s developer software, Xcode, that lets you collect, display, and track the valuable metrics hiding inside your team’s Xcode build logs. Are your build times improving or regressing? Which version of Xcode is slowest? Which hardware setup is fastest? XCMetrics makes it…
By Spotify engineers · Spotify · Added 2026-10-12
All content belongs to Spotify engineers / Spotify. We only link to it and give credit. Report a problem
Learn this case study
About 37 min left. Your work is saved as you go.
What you are about to study
Spotify explains a real system. You should know the basics: caching, queues and replication.
Ideas you will meet
- Distributed Systems
- Consensus, time, failure and the fundamentals of scale-out.
- Observability
- Metrics, logs, traces, SLOs and alerting.
What we already know about this
Our own lessons on these ideas. Read them here before you start, so it makes sense.
System Design Foundations · 9 minObservability and running a systemMetrics, logs and traces, how to define 'healthy' with SLOs, and how to ship changes without breaking things.Read here
You cannot fix what you cannot see
A system you cannot observe is a system you cannot trust. Observability is the ability to understand what is happening inside from the outside. Three kinds of signal work together.
Signal What it is Best for Metrics Numbers over time (requests per second, error rate, CPU) Dashboards, alerts, trends Logs Timestamped records of events Details of what happened Traces The path of one request through many services Finding where time is spent 100%Figure SDA-FND-11-1 · From alert to root cause · © forcsguy.com
What to measure
A simple checklist, the four golden signals:
- Latency: how long requests take (use percentiles).
- Traffic: how much demand there is.
- Errors: how many requests fail.
- Saturation: how full the busiest resource is (CPU, memory, connections, disk, queue depth).
Averages hide pain. If the average is 100 ms but p99 is 4 seconds, one user in a hundred is waiting four seconds, and with many requests per page that is most of your users sometimes.
Defining healthy: SLIs, SLOs, error budgets
- An SLI (indicator) is a measurement, like "fraction of requests answered successfully in under 300 ms".
- An SLO (objective) is the target, like "99.9% over 30 days".
- The error budget is what is left over: 0.1% of requests may fail. While there is budget, ship features; when it runs out, focus on reliability.
Alert on symptoms users feel (error rate, latency) more than on causes (one machine's CPU). Page a human only for things that need action now.
Ship changes safely
Most outages come from changes. Reduce the risk:
- Small, frequent releases are easier to understand and undo than big ones.
- Canary release: send a few percent of traffic to the new version and watch the metrics before going wider.
- Feature flags: deploy code turned off, then enable it gradually, and switch it off instantly if needed.
- Blue-green: keep the old version running so you can switch back in seconds.
- Backwards-compatible changes: database and API changes should work with both old and new code during rollout.
- Fast rollback must be a rehearsed, boring button.
When things go wrong
Have an incident process: someone leads, someone communicates, mitigate first and investigate later. Afterwards write a blameless postmortem that asks "how did our system and process allow this?" rather than "who did this?". That is how reliability actually improves.
A worked example: error budgets and burn rate
Your service has an SLO of 99.9% of requests succeed over 30 days, and it serves 10 million requests a month.
- Error budget: 0.1% of 10,000,000 = 10,000 failed requests may happen in the month before you break the promise.
- Burn rate is how fast you spend it. A burn rate of 1 uses exactly the budget over 30 days. If 5% of requests are failing now, the error rate is 50 times the allowed 0.1%, a burn rate of 50: the whole month's budget is gone in 30 / 50 = 0.6 days, about 14 hours.
- Alert on burn rate, not on a single bad minute. A common pattern watches two windows together: page someone if the burn rate over the last hour is above about 14 and the last 5 minutes agree (a fast burn: 2% of the monthly budget gone in an hour). Open a ticket for a slower burn, say rate above 6 over 6 hours. Two windows avoid paging for blips and avoid missing slow leaks.
Why this beats "alert when error rate is above X": it ties alerts to what users were promised, it pages only when the budget is in danger, and it gives the team a rule for trade-offs: when the budget is healthy, ship faster; when it is nearly spent, slow down and fix reliability.
100%Figure SDA-FND-11-2 · Alerting on how fast the error budget burns · © forcsguy.com
Finding the cause with all three signals
A worked investigation shows why you want metrics, traces and logs together.
- A metric alerts: the checkout success rate dropped and p99 latency rose. Metrics tell you that something is wrong and how bad, cheaply and over time.
- Narrow it down by dimension: break the metric down by region, version and endpoint. Only the new version in one region is affected, a strong hint it is a deploy.
- A trace shows where the time goes: one slow checkout request shows 4.8 of its 5 seconds in a call to the payment provider's tokenisation endpoint.
- Logs give the detail: filter logs by the trace id from that request and read the exact error: a timeout talking to a new tokenisation URL.
- Fix and verify: roll back the version, and watch the metric recover.
100%Figure SDA-FND-11-3 · From an alert to a root cause · © forcsguy.com
The glue is a correlation id (trace id) carried on every request and written into every log line, so you can jump from one signal to the others.
Mistakes people make
- Alerting on causes instead of symptoms. "CPU is 85%" may be fine; "users are seeing errors" never is. Page on symptoms users feel, and use cause metrics for diagnosis.
- Averaging percentiles. The mean of two hosts' p99 is meaningless; merge distributions instead (see the t-digest lesson).
- High-cardinality labels. A label such as
user_idon a metric creates a new time series per user, which can multiply storage and cost by millions. Put such detail in logs or traces. - Logs without structure or ids. Free text is hard to query. Log JSON with a trace id, service and version.
- Dashboards no one owns. A wall of graphs nobody reads is noise. Build a small dashboard per service around the golden signals: latency, traffic, errors and saturation.
- No runbook. An alert that does not say what to check first wastes the first ten minutes of every incident.
Try it yourself
Run any test in the System Builder and read its charts as if they were production graphs: which signal moves first, and which part would you look at next? Build the search metrics lab to practise percentile maths, and read the t-digest lesson for how real systems summarise latency at scale.
Real-world reading
Related reading
- The Site Reliability WorkbookGoogle SRE team · O'Reilly / GoogleBooks
- Feature Toggles (aka Feature Flags)Pete Hodgson · Martin FowlerBlogs
- InfluxData BlogInfluxData engineers · InfluxDataBlogs
- MetricsDB: TimeSeries Database for storing metrics at TwitterTwitter engineers · TwitterCase Studies
Show 6 moreShow fewer
- The Architecture Twitter Uses to Deal with 150M Active Users, 300K QPS, a 22 MB/S Firehose, and Send Tweets in Under 5 SecondsHigh Scalability engineers · High ScalabilityCase Studies
- Steady State: Always Put Logs on Separate DiskMicrosoft engineers · MicrosoftCase Studies
- XCMetrics: All-in-One Tool for Tracking Xcode Build Metrics at SpotifySpotify engineers · SpotifyCase Studies
- Honeycomb BlogHoneycomb engineers · HoneycombBlogs
- BookKeeper: Distributed Log Storage at YahooYahoo engineers · YahooCase Studies
- Analyzing V8 Garbage Collection Logs at AlibabaAlibaba engineers · AlibabaCase Studies
Messaging and Microservice Patterns · 13 minObservability: metrics, SLIs, SLOs and alertingTurning raw signals into targets people can act on: the three pillars, the four golden signals, SLIs, SLOs, error budgets and alerts that wake you only when it matters.Read here
Monitoring versus observability
Monitoring watches known questions ("is the error rate high?"). Observability is the ability to ask new questions of a running system from the data it emits, which matters when failures are unexpected. It rests on three signal types, often called the pillars:
Signal What it is Good for Metrics Numbers over time (counts, rates, durations) Dashboards, alerts, trends; cheap to store Logs Timestamped event records Detail about what happened in one place Traces A request's path across services Finding where time and errors come from Together with context (deploy markers, config changes) they let you move from "something is wrong" to "this is why". (Collection architecture is in the metrics monitoring lesson; instrumentation in the previous lesson.)
What to measure
Two handy checklists:
- The four golden signals (for services): latency (separate successful from failed), traffic (demand), errors (rate of failures) and saturation (how full the most constrained resource is).
- RED for request-driven services (Rate, Errors, Duration) and USE for resources (Utilisation, Saturation, Errors).
Use percentiles (p50, p95, p99) rather than averages for latency, because averages hide the slow tail that users feel (see the latency lesson). Keep label cardinality low (do not label metrics with user ids).
SLIs, SLOs and SLAs
100%Figure SDA-MSV-06-1 · From measurement to promise · © forcsguy.com
- SLI (indicator): a ratio of good events to valid events, such as
successful requests / valid requestsorrequests under 300 ms / all requests. - SLO (objective): a target for the SLI over a window. Few, meaningful SLOs beat many.
- SLA (agreement): the contractual promise and what happens if missed; keep it looser than the SLO so you have room to react.
- Error budget =
1 - SLO. With 99.9 percent over 30 days you may be "down" about 43 minutes. Common reference points: 99 percent ≈ 7.2 hours a month, 99.9 percent ≈ 43 minutes, 99.99 percent ≈ 4.3 minutes.
Using the budget: while budget remains, ship features and take risks; when it is nearly spent, prioritise reliability work. This turns arguments between "ship faster" and "be safer" into a shared, measurable policy.
Alerting that deserves a human
Alert fatigue is a reliability problem: people ignore noisy pages.
- Alert on symptoms, not causes: "users see errors" rather than "one pod restarted". Keep cause metrics for dashboards and diagnosis.
- Every page must be urgent, actionable and with a runbook; if not, make it a ticket or delete it.
- Use burn-rate alerts: page when the error budget is being consumed much faster than allowed (for example 2 percent of a 30-day budget in an hour), ticket for slow burns. Use two windows (short and long) to be fast but not flappy.
- Group and deduplicate related alerts; route by ownership; add severity.
- Review alerts after incidents and prune them regularly.
100%Figure SDA-MSV-06-2 · From signal to action · © forcsguy.com
The tools, in one table
Need Common tools Metrics collection and alert rules Prometheus (pull model), cloud metrics, Datadog Dashboards Grafana, vendor dashboards Logs ELK or OpenSearch stack, Loki, Splunk, cloud logging Traces Jaeger, Zipkin, Tempo, vendor APM Instrumentation standard OpenTelemetry Incident paging PagerDuty, Opsgenie and similar Dashboards that help
One overview per service showing the golden signals and SLO burn; drill-down panels for dependencies and resources; deploy and config markers on graphs; and consistent layout across services so anyone on call can read any of them.
Incidents and learning
Have on-call rotations with clear escalation, runbooks for known failures, and blameless post-incident reviews that produce concrete follow-ups. Practise with game days. Reliability is a process as much as a technology: measure, set targets, spend the budget wisely, and learn from every failure.
Real-world reading
Related reading
- The Site Reliability WorkbookGoogle SRE team · O'Reilly / GoogleBooks
- Google SRE Book: Service Level ObjectivesGoogle SRE team · GoogleBlogs
- Alerting on Service-Level Objectives (SLOs) at SoundCloudSoundCloud engineers · SoundCloudCase Studies
- PrometheusPrometheus · CNCF / PrometheusGitHub
Show 6 moreShow fewer
- Prometheus overviewPrometheus · CNCF / PrometheusDocumentation
- Google SRE Book: Monitoring Distributed SystemsGoogle SRE team · GoogleBlogs
- Grafana LabsGrafana Labs engineers · Grafana LabsBlogs
- Monitoring and Alert System using Graphite and Cabot at HackerEarthHackerEarth engineers · HackerEarthCase Studies
- Kotlin at DoorDashDoorDash engineers · DoorDashCase Studies
- ThirdEye: Monitoring Platform at LinkedInLinkedIn engineers · LinkedInCase Studies
Software Design Essentials · 9 minCreational patterns: Factory, Builder, SingletonWays to create objects without hard-wiring the exact class: factories, builders, prototypes and why Singleton is usually a last resort.Read here
The goal
Creational patterns manage how objects are created, so the rest of the code does not depend on exact classes or messy construction steps.
Factory Method (and simple factories)
Callers ask for what they need, and a factory decides which concrete class to create.
interface Sender { send(to: string, text: string): Promise<void> } class EmailSender implements Sender { async send(to: string, text: string) { /* ... */ } } class SmsSender implements Sender { async send(to: string, text: string) { /* ... */ } } function createSender(channel: "email" | "sms"): Sender { switch (channel) { case "email": return new EmailSender(); case "sms": return new SmsSender(); } } await createSender(user.preferredChannel).send(user.contact, "Your code is 482913");Benefits: one place to change when classes change, callers depend only on the interface, and tests can supply fakes. A registry (a map from name to constructor) makes adding a type a one-line change.
Factory Method as a picture
100%Figure SDA-SDE-03-1 · Calling code, factory and products · © forcsguy.com
Abstract Factory
Create families of related objects that must be used together, such as a UI toolkit's button, checkbox and menu for one platform or theme.
interface UiFactory { button(): Button; checkbox(): Checkbox } class DarkUi implements UiFactory { /* returns dark variants */ } class LightUi implements UiFactory { /* returns light variants */ }Use it when several products must stay consistent. Skip it when you only vary one object.
Builder
Construct a complex object step by step, especially with many optional parts. In languages with named parameters or option objects this is often just that.
const request = new RequestBuilder("https://api.example.com/orders") .method("POST") .header("Authorization", token) .json({ items }) .timeout(5000) .build(); // validates and returns an immutable RequestBenefits: readable construction, validation in one place, and immutable results. The alternative, a constructor with ten positional parameters, is easy to misuse.
Prototype
Create new objects by copying an existing one, useful when creation is expensive or when you want variations of a configured template.
const base = { retries: 3, timeout: 2000, headers: { accept: "json" } }; const slow = { ...base, timeout: 10000 }; // shallow copy with a change const deep = structuredClone(base); // deep copyBeware shallow versus deep copies: sharing nested objects causes surprising bugs.
Singleton
Ensures only one instance exists and gives global access to it.
class Config { private static instance?: Config; static get(): Config { return (Config.instance ??= new Config()); } }It looks convenient but has real costs: hidden dependencies, global mutable state, difficulty in testing (state leaks between tests), and trouble with concurrency. Often what you really need is one instance, not global access.
Better: create the single instance once, in the application's start-up code (the composition root), and inject it into what needs it. You keep "only one" without making it global.
Choosing
Situation Pattern Which class to create depends on input or configuration Factory Method or a registry Several related objects must match Abstract Factory Many optional parts, validation needed Builder or an options object Cloning a configured template Prototype or a copy "There should be only one" Create one in the composition root and inject it Prefer the lightest form your language offers: a function that returns an object is often all the "factory" you need.
Real-world reading
Related reading
- Ambry: Distributed Immutable Object Store at LinkedInLinkedIn engineers · LinkedInCase Studies
- XCMetrics: All-in-One Tool for Tracking Xcode Build Metrics at SpotifySpotify engineers · SpotifyCase Studies
- Hugging Face BlogHugging Face engineers · Hugging FaceBlogs
- Design Patterns CatalogueRefactoring GuruDocumentation
Show 6 moreShow fewer
- The Twelve-Factor AppAdam Wiggins · 12factor.netDocumentation
- Scaling Global CDN at Netflix - Dave Temkin, Director of Global Networks at NetflixNetflixYouTube
- 8 Things You Need to Know Before a System Design InterviewGainlo engineers · GainloBlogs
- Cloud Object Store at YahooYahoo engineers · YahooCase Studies
- Dynamometer: Scale Testing HDFS on Minimal Hardware with Maximum Fidelity at LinkedInLinkedIn engineers · LinkedInCase Studies
- Kakao Blog (Korean)Kakao engineers · KakaoBlogs
Want the architecture first? Read our Spotify case study, with its diagram.
Go deeper on this
A path through videos, articles, other case studies and code on the same ideas as XCMetrics: All-in-One Tool for Tracking Xcode Build Metrics at Spotify.
Warm upGet the vocabulary first.
Books · Free from the author
Concurrent and Distributed Systems (Cambridge lecture notes)
Eight lectures on time, broadcast, replication, consensus and transactions, with notes, slides and video. Free from the author under CC BY-SA.
University of CambridgeIntermediate
Books · Free from the author
Computer Networks: A Systems Approach
How networks are built and why: protocols, routing, congestion control and the internet's architecture. The authors publish it free online under CC BY 4.0.
Systems ApproachIntermediate
WatchHow others solve the same problem, on video.
Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)
ReadEngineers explain it in their own words.
Papers
Dapper: a Large-Scale Distributed Systems Tracing Infrastructure (paper)
The paper behind distributed tracing: spans, trace ids and low-overhead sampling.
GoogleAdvanced
Blogs · Free from the author · Read here
Scalable Web Architecture and Distributed Systems
A full chapter on the building blocks of large websites: availability, performance, reliability, scalability, caches, proxies, indexes, load balancers and queues. Free to read here under CC BY 3.0.
The Architecture of Open Source ApplicationsBeginner40 min
See it in another companyThe same ideas, a different system.
Case Studies · Read here
Improve Zipkin Traces using Kubernetes Pod Metadata at SoundCloud
We revisited our distributed tracing setup and incorporated Kubernetes pod metadata into it, significantly enhancing our engineers’ ability to troubleshoot problems that cut across microservices.
SoundCloudIntermediate
Case Studies · Read here
Real-time Distributed Tracing at LinkedIn
Co-authors: Chris Coleman , Toon Sripatanaskul With LinkedIn’s service-oriented architecture, a single page view request can fan out calls to downstream services spanning multiple backend tiers, many levels deep. Thou...
LinkedInIntermediate
Read the codeSee how it looks when it is real.
GitHub
Engineering Blogs
A huge directory of company engineering blogs to learn from real production systems.
kilimchoiIntermediate
GitHub
Awesome Scalability
Curated reading list of articles on the architecture of scalable, reliable systems.
binhnguyennusIntermediate
Keep learning
Loading community…