Platform · Enterprise

Measure DORA Metrics with the Four Keys Pipeline, Pub/Sub and BigQuery

Deploy a Four Keys style pipeline that turns Git and deployment events into deployment frequency, lead time for changes, change failure rate and time to restore, in BigQuery with a dashboard.

  • Four Keys
  • DORA
  • BigQuery
  • Pub/Sub
  • Cloud Run
  • GitHub webhooks
  • SQL
  • Looker Studio

// Why this matters

If you want to set up DORA metrics with a Four Keys pipeline, you are really asking whether your delivery process is getting faster and safer. Opinions about that are easy and unreliable. Four numbers computed from real events, deployment frequency, lead time for changes, change failure rate and time to restore, give an honest baseline and let you see whether a change to the pipeline helped.

For a platform team this is also how you justify investment. If you build self-service tooling like From Form to Running Cluster: Self-Service Team Onboarding or reusable pipelines like One Reusable Plan/Apply Workflow for Cost-Optimised Autoscaling, delivery metrics are the evidence that teams ship more smoothly afterwards.

// The problem

The hard part of DORA is not the arithmetic, it is the data. Deployments happen in several tools, incidents live in another, and commits in a third. Teams define deployment differently: one counts a merge, another counts a production rollout, a third counts a successful release job. Metrics built on mismatched definitions are noise and invite argument rather than action.

There is also a misuse risk. Metrics turned into targets get gamed: split commits to inflate frequency, reclassify incidents to lower failure rate. A pipeline has to make the data trustworthy and the presentation constructive.

// The solution

The Four Keys design is simple and durable. Events are captured as raw JSON from webhooks: pushes and pull requests from the Git host, deployment events from CI or the deploy tool, and incident open and close events from the incident tool. A small ingestion service verifies the webhook signature, adds a source label and publishes the event to Pub/Sub. A BigQuery subscription lands it in a raw events table.

Everything else is SQL on top. A changes view extracts commits and the time they were merged. A deployments view extracts successful production deployments with their commit SHA and time. An incidents view pairs open and close events. Lead time is the time from first commit (or merge) to the deployment that contains it, joined by SHA. Change failure rate is the share of deployments linked to an incident or rollback. Time to restore is the median incident duration.

Because raw events are stored untouched, you can revise definitions later and recompute history. That is the main reason to keep the raw table rather than only aggregates. Per-team slicing uses a mapping from repository to team maintained alongside the pipeline.

I rejected scraping the Git API periodically (misses deployment context and hits rate limits) and rejected a vendor product as a first step because the definitions are what matter, and writing them in SQL forces the conversation. Dashboards show weekly medians and trends per team; the goal is to find the slow step, not to rank people. The BigQuery landing pattern is the same one used in Terraform Modules for Cloud Composer, BigQuery Datasets and Pub/Sub to BigQuery Sinks.

How it flows flow1. Define → 2. Webhooks → 3. Ingest → 4. Gate: signature → 5. Land → 6. Transform → 7. Join → 8. Compute → 9. Dashboard01Define02Webhooks03Ingest04 · GATEGate: signature05Land06Transform07Join08Compute09Dashboard
How it flows. End-to-end flow. Dashed pink nodes are gates: points where a human or a check must pass before the next stage runs.
  1. Defineagree what counts as a deployment, change and incident
  2. WebhooksGit, CI and incident tools post events
  3. Ingestsmall service verifies signature and publishes to Pub/Sub
  4. Gate: signature gateunsigned or invalid events are dropped
  5. Landsubscription writes raw events to BigQuery
  6. TransformSQL views build changes, deployments and incidents
  7. Joinlink deployments to commits by SHA for lead time
  8. Computefour metrics per team and period
  9. Dashboardtrends charted for the teams that own them
Git hostIngest servicePub/SubBigQueryDashboardPOST event with HMAC signaturesignature verified, 204 returnedpublish eventsubscription writes raw rowviews derive changes and deploymentsquery weekly medians per team
From webhook to metric. Only the ingestion service sees the signing value; everything downstream is data.
SourcesGit pushes and PRsdeployment eventsincident eventsIngestionsignature checksource tagPub/Sub topicStorageraw events tablerepo to team mapDerivationchanges viewdeployments viewincidents viewPresentationfour metrics viewteam dashboard
Pipeline layers. Definitions live in the SQL layer, so they can change without losing history.

// Before you start

  • A cloud project with BigQuery, Pub/Sub and Cloud Run enabled
  • Admin rights to create webhooks on the Git host (organisation level is easiest)
  • A CI or deployment tool that can emit a deployment event, and an incident tool that can post webhooks
  • A shared webhook signing value stored in a secret manager
  • A written definition of deployment and incident agreed by the teams
  • Basic SQL, including window functions and JSON extraction

// Step-by-step implementation

  1. 01 Step 1. Write down the definitions

    Before any code, agree the definitions in a short document the teams sign off. Typical choices: a deployment is a successful rollout to production; a change is a commit that reaches the default branch; an incident is an open and close pair in the incident tool linked to a service; a failure is a deployment followed by an incident or rollback within a set window.

  2. 02 Step 2. Create the raw events table and topic

    Store each event as raw JSON along with source, event type, time and a signature id. Partition by day and cluster by source to keep queries cheap.

  3. 03 Step 3. Build the signed-webhook ingestion service

    The service verifies the HMAC signature header, tags the source and publishes to Pub/Sub. Reject anything unsigned. Run it on Cloud Run with an unauthenticated invoker (webhooks cannot present cloud identity), relying on the signature as the authentication.

  4. 04 Step 4. Deploy the service and register the webhooks

    Deploy to Cloud Run, store the signing value in the secret manager and mount it as an environment variable. Then create an organisation webhook pointing at the service with the same value, for push, pull request and deployment events.

  5. 05 Step 5. Derive changes and deployments with SQL views

    These views encode the definitions. Extract the commit SHA and times from the JSON payloads. Keep one view per concept so they are easy to review.

  6. 06 Step 6. Compute lead time and deployment frequency

    Lead time is the gap between a commit and the production deployment containing it. Because deployments carry only the head SHA, a common approach links by SHA exactly and falls back to the next deployment after the commit time. Use the median, not the mean, since a few slow outliers distort averages.

  7. 07 Step 7. Compute change failure rate and time to restore

    Incidents come from the incident tool as open and close events. Link a failure to a deployment when an incident opens within your window after it. Time to restore is incident duration.

// How to verify it works

  • Post a signed test payload to the ingest service and see one row in fourkeys.events_raw within a minute; an unsigned post returns 403.
  • SELECT COUNT(*) FROM fourkeys.deployments increases after a real production deployment, with the correct SHA.
  • Pick a recent commit and confirm fourkeys.lead_time shows the gap to the deployment that contained it.
  • Open and close a test incident; fourkeys.incidents shows both timestamps and a duration.
  • The dashboard shows weekly deployments and a plausible failure rate per team; spot-check one week by hand.

// Design decisions and trade-offs

  • Collect events by webhook, store them raw in BigQuery, and derive metrics with views, so definitions can change without losing history.
  • Define a deployment, a change and an incident explicitly before writing any SQL; the numbers are only as good as those definitions.
  • A thin ingestion service validates webhook signatures and publishes to Pub/Sub, decoupling producers from storage.
  • Link deployments to commits by SHA, which is the join that gives lead time.
  • Present trends and medians per team, not leaderboards, to avoid metric gaming.

// Pitfalls and lessons learned

  • Fuzzy definitions. If teams disagree on what a deployment is the numbers are meaningless; write definitions first.
  • Duplicate webhook deliveries. Retries create duplicates unless you de-duplicate by delivery id.
  • Using averages. A single stalled change skews mean lead time; report medians and distributions.
  • Squash and rebase merges change SHAs. Link by pull request or merge commit rather than only the original commit.
  • Turning metrics into targets. Teams will game them; use trends to find bottlenecks, not to rank people.
  • Missing incident data. Without consistent incident logging the failure rate looks perfect for the wrong reason.

// Frequently asked questions

How do I set up DORA metrics with Four Keys?

Capture Git, deployment and incident events by webhook into BigQuery through Pub/Sub, then use SQL views to compute deployment frequency, lead time, change failure rate and time to restore.

How do I calculate lead time for changes?

Join each commit to the first production deployment at or after it, by SHA and repository, and take the time difference, reporting the median.

What counts as a deployment for DORA?

Teams define it, but a successful rollout to production is the usual choice. Whatever you pick, apply it consistently across teams.

How do I calculate change failure rate?

Divide deployments that led to an incident or rollback within a fixed window by total deployments in the period.

// The outcome

A working measurement pipeline: events flow from the source platforms into BigQuery, and the four delivery metrics are computed from views and charted per team.

// Where to take it next

// Keep reading