Event contract
Fields the query expects
| Field | Type | Why it exists |
|---|---|---|
| timestamp_utc | Timestamp | Terminal transaction time in UTC. |
| transaction_id | Utf8 | Application-generated identifier for one logical transaction. |
| service | Utf8 | Application or worker that owned the transaction. |
| database_name | Utf8 | Approved logical database name. |
| status | Utf8 | committed or rolled_back. |
| error_type | Utf8 | Controlled rollback category such as deadlock or serialization_failure. |
| duration_ms | Float64 | End-to-end logical transaction duration. |
| account_id | Utf8 | Approved customer or tenant identifier used for impact analysis. |
| environment | Utf8 | Deployment environment. |
Copy the query
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.
| service | database_name | transactions | rollbacks | rollback_rate_pct | affected_accounts | average_duration_ms |
|---|---|---|---|---|---|---|
| checkout-api | app_production | 12 | 3 | 25 | 3 | 290 |
| billing-worker | billing_production | 12 | 1 | 8.33 | 1 | 275 |
| catalog-api | catalog_production | 12 | 0 | 0 | 0 | 107.5 |
Synthetic example output. Run the query against your own event schema and thresholds before using it for operational decisions.
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
- 1The numerator counts terminal rolled-back transactions, not every retry attempt.
- 2Affected accounts add customer context without changing the transaction denominator.
- 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 setupPut the recipe to work
Related instrumentation and guides
Continue the analysis
Find Slow Database Queries by Fingerprint
Rank normalized database operations by slow-query rate, average duration, and worst observed duration without storing raw SQL or parameters.
Open recipeMeasure Database Connection-Pool Saturation
Measure average pool utilization, queued acquisition waits, timeouts, and idle capacity by application service.
Open recipeFind Database Lock Waits and Deadlocks
Rank blocked database operation fingerprints by incident count, wait duration, unresolved locks, and detected deadlocks.
Open recipeRun 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.