Telemetry
Database reliability SQL recipe

Calculate Database Transaction Rollback Rate

Compare committed and rolled-back transactions by service while preserving error categories, duration, and affected accounts.

Intermediatedatabase_transaction_eventsReviewed 2026-07-28Tested with Apache DataFusion 45.2.0

Reviewed by the Telemetry product team on . SQL compatibility, event contract, synthetic output, and operational caveats. Editorial ownership

Question answered

Which services roll back an unusual share of database transactions?

A rollback can be an expected concurrency response or a user-visible failure. Measuring its rate by service and database identifies where application transaction policy deserves a closer review.

Event contract

Fields the query expects

FieldTypeWhy it exists
timestamp_utcTimestampTerminal transaction time in UTC.
transaction_idUtf8Application-generated identifier for one logical transaction.
serviceUtf8Application or worker that owned the transaction.
database_nameUtf8Approved logical database name.
statusUtf8committed or rolled_back.
error_typeUtf8Controlled rollback category such as deadlock or serialization_failure.
duration_msFloat64End-to-end logical transaction duration.
account_idUtf8Approved customer or tenant identifier used for impact analysis.
environmentUtf8Deployment environment.
DataFusion SQL

Copy the query

sql
SELECT
  service,
  database_name,
  COUNT(*) AS transactions,
  SUM(CASE WHEN status = 'rolled_back' THEN 1 ELSE 0 END) AS rollbacks,
  100.0 * SUM(CASE WHEN status = 'rolled_back' THEN 1 ELSE 0 END)
    / NULLIF(COUNT(*), 0) AS rollback_rate_pct,
  COUNT(DISTINCT CASE
    WHEN status = 'rolled_back' THEN account_id
    ELSE NULL
  END) AS affected_accounts,
  AVG(duration_ms) AS average_duration_ms
FROM database_transaction_events
WHERE timestamp_utc >= now() - INTERVAL '7 days'
  AND environment = 'production'
GROUP BY service, database_name
HAVING COUNT(*) >= 10
ORDER BY rollback_rate_pct DESC, transactions DESC;

This read-only query is planned and executed against an empty typed table with Apache DataFusion 45.2.0. The deterministic sample output is synthetic and reviewed separately; validate field types, thresholds, and business definitions against your own data. Read the testing methodology.

Query result

Transaction rollback rate by service

Checkout has both the highest rollback rate and the largest affected-account count.

servicedatabase_nametransactionsrollbacksrollback_rate_pctaffected_accountsaverage_duration_ms
checkout-apiapp_production123253290
billing-workerbilling_production1218.331275
catalog-apicatalog_production12000107.5

Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.

Transaction rollback rate by service: static chart of synthetic rollback_rate_pct values from the Calculate Database Transaction Rollback Rate example result
Indexable SVG of the deterministic example output. Download it for an article, runbook, or design review with attribution.

Reproduce the example

Download the public fixture

The JSON bundle includes the typed event contract, reproducible input rows, exact SQL, expected output, review notes, and engine version. The CSV contains the displayed result.

How the SQL works

  1. 1The numerator counts terminal rolled-back transactions, not every retry attempt.
  2. 2Affected accounts add customer context without changing the transaction denominator.
  3. 3A controlled error_type should be examined separately to distinguish expected serialization retries from application defects.

Edge cases to decide

  • One logical operation may retry several transactions. Keep a workflow ID if you also need final user outcome.
  • Read-only transactions may have a different baseline and should be segmented when relevant.
  • Do not log statement parameters, connection strings, or unrestricted error messages.

Recommended dashboard

  • Bars: rollback_rate_pct by service
  • Stacked trend: commits and rollbacks over time
  • Table: rollback error_type by release and affected account count

Alert guidance

Alert on a sustained rollback-rate increase with meaningful transaction volume, then separate retryable concurrency errors from final failures.

Read alert setup

Put the recipe to work

Related instrumentation and guides

Continue the analysis

Run it on real events

Create a table, adapt the fields, and save the result

Start free, send structured events, and use the query result as a chart, shared dashboard widget, or alert input.

Get an API key