Skip to content

Debug any bug

Time travel to any point and replay exactly what happened

“The bug happened last Tuesday. A customer’s balance was wrong, but we fixed the data. Can you figure out what went wrong?”

With traditional databases, this conversation ends with “we’ll add more logging next time.”

With event sourcing, this conversation starts with “let me show you exactly what happened.”

Your customer calls: “My account shows $50, but I only deposited $30. What happened?”

Traditional database debugging:

SELECT * FROM accounts WHERE id = 'customer-123';
-- balance: 50
-- How did we get here? Nobody knows.

You check logs. Maybe you find some traces. You make educated guesses. You promise to add more monitoring.

Event sourcing debugging:

// Show me exactly what happened
const events = await eventStore.readStream('customer-123');
console.log(events);
// [
// { type: 'AccountOpened', timestamp: '2024-01-01T10:00:00Z' },
// { type: 'MoneyDeposited', amount: 30, timestamp: '2024-01-01T10:05:00Z' },
// { type: 'MoneyDeposited', amount: 20, timestamp: '2024-01-01T10:06:00Z' },
// ]

There it is. Two deposits. The customer forgot about the second one.

A customer got charged an overdraft fee, but their balance never went negative in your UI.

The investigation:

// What was the account state when the fee was charged?
const eventsBeforeFee = await eventStore.readStream('account-456', {
before: '2024-01-15T14:30:00Z' // Fee timestamp
});
// Replay the state
let balance = 0;
for (const event of eventsBeforeFee) {
if (event.type === 'MoneyDeposited') balance += event.amount;
if (event.type === 'MoneyWithdrawn') balance -= event.amount;
}
console.log(`Balance before fee: $${balance}`);
// Balance before fee: $-5
// What caused the negative balance?
const lastWithdrawal = eventsBeforeFee
.filter(e => e.type === 'MoneyWithdrawn')
.pop();
console.log(lastWithdrawal);
// {
// type: 'MoneyWithdrawn',
// amount: 25,
// timestamp: '2024-01-15T14:25:00Z',
// metadata: { source: 'mobile_app_v2.1.0' }
// }

The bug: Mobile app v2.1.0 had a race condition. Two withdrawal requests processed simultaneously.

Traditional debugging: Would take days, maybe weeks. Probably never find the root cause.

Event sourcing debugging: 5 minutes. Exact cause identified. Bug fixed.

Auditor: “Prove that this $10,000 transfer was authorized and processed correctly.”

Traditional approach: Export database tables, hope the audit trail is complete, pray you have all the logs.

Event sourcing approach:

// Show complete audit trail
const transferEvents = await eventStore.readStream('transfer-789');
for (const event of transferEvents) {
console.log(`${event.timestamp}: ${event.type}`);
console.log(` User: ${event.metadata.userId}`);
console.log(` Data: ${JSON.stringify(event.data)}`);
}
// Output:
// 2024-01-15T09:00:00Z: TransferInitiated
// User: user-123
// Data: { fromAccount: 'acc-1', toAccount: 'acc-2', amount: 10000 }
//
// 2024-01-15T09:00:01Z: TransferAuthorized
// User: user-123
// Data: { authMethod: 'sms_code', code: '123456' }
//
// 2024-01-15T09:00:02Z: FundsReserved
// User: system
// Data: { fromAccount: 'acc-1', amount: 10000 }
//
// 2024-01-15T09:00:03Z: TransferCompleted
// User: system
// Data: { transferId: 'transfer-789', completedAt: '2024-01-15T09:00:03Z' }

Complete proof of authorization, processing, and completion. Auditor is happy. You’re done in 10 minutes.

The magic isn’t just debugging past problems. It’s preventing future ones.

Reproduction: Found a bug? Replay the exact event sequence in your test environment.

Root cause analysis: Events show not just what happened, but why it happened.

Impact assessment: Replay events to see how many customers were affected.

Fix validation: Apply the fix and replay events to prove it works.

Traditional systems lose information. Event sourcing preserves everything.

  • Know exactly what happened - No guessing, no incomplete logs
  • Reproduce any scenario - Replay events in test environments
  • Prove compliance - Complete audit trails for everything
  • Debug across time - See how issues developed over days or weeks

Your future self will thank you when production breaks at 3am and you can see exactly what went wrong instead of staring at cryptic error messages.

That’s the power of events. That’s the power of DeltaBase.