Skip to content
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 . We checked the SQL syntax, required event fields, sample results, and limits on using the query. Who reviews this page

Question answered

Which services roll back an unusual share of database transactions?

Some rollbacks recover on retry. Others fail the user's request. Compare rollback rates by service and database, then check which transaction errors need a retry policy change.

Event schema

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. We review the synthetic sample output separately. Check field types, thresholds, and counting rules 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
Download this SVG chart of the sample results for an article, runbook, or design review. Please credit Telemetry.

Reproduce the example

Download the sample data

The JSON bundle includes the event schema with field types, 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 final 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 check

  • 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 after the transaction count meets your minimum. Separate retryable concurrency errors from final failures.

Read alert setup

Set up the events this query needs

Related instrumentation and guides

Continue the analysis

Run it on your 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