Why I'm Building PesaGuard on Event-Driven Architecture, Not Batch

Why I'm Building PesaGuard on Event-Driven Architecture, Not Batch

Most reconciliation tools I looked at before starting PesaGuard were built the same way: pull M-Pesa statements at the end of the day, diff them against internal records, flag whatever doesn't match. It works, until it doesn't. A SACCO or small fintech running batch reconciliation finds out about a mismatched transaction 12 hours after it happened. Long after the money has moved, the member has walked away, or the fraud pattern has repeated three more times.

That gap is the whole argument for event-driven architecture, and it's why PesaGuard isn't built around nightly jobs.

The batch failure mode

Batch reconciliation has a structural problem: it treats "when did this happen" and "when did we find out" as the same thing, when they're not. A SACCO processing a few hundred M-Pesa transactions a day might only run reconciliation once. Meaning every anomaly, from a genuine fraud attempt to a simple duplicate charge, sits undetected until the next batch window opens. For a small fintech handling higher volume, that delay compounds: by the time you catch the pattern, you're explaining it to a customer instead of preventing it.

The fix isn't "run batch more often." It's rethinking the transaction as an event you react to the moment it happens, not a row you inspect later.

How the pipeline actually works

PesaGuard's core flow looks like this:

  • Daraja webhook: M-Pesa's C2B/B2B callbacks land as HTTP events the moment a transaction completes.
  • Event bus: each callback is published onto a stream rather than written straight to a database and forgotten. This is the architectural pivot: the transaction becomes an event other consumers can subscribe to, not a static record.
  • Anomaly detection consumer: a downstream service subscribes to the stream and runs rule-based and statistical checks (duplicate transaction IDs, amount mismatches, velocity spikes) against each event as it arrives.
  • Alerting / reconciliation store: flagged events get written to a review queue; everything else gets reconciled against internal ledgers in near real time instead of overnight.
BATCH                                  EVENT-DRIVEN
M-Pesa statement (EOD)                 Daraja webhook (per-transaction)
        |                                      |
        v                                      v
  Nightly diff job                       Event bus / stream
        |                                      |
        v                                      v
  Flagged mismatches                   Anomaly detection consumer
  (discovered next day)                        |
                                                v
                                   Flagged in near real time

What this costs you

Event-driven isn't free. Moving off batch means taking on:

  • Ordering and idempotency problems: Daraja can retry webhooks; your consumer has to handle duplicate events without double-flagging or double-crediting.
  • Operational surface area: a stream and a consumer service is more to monitor than a cron job. If the consumer falls behind, you need lag visibility, not just a "did the job run" check.
  • Harder debugging: replaying "what did the system know at 2:14pm" is a different exercise than rerunning yesterday's batch script.

For a solo build, that's a real trade-off. But for a reconciliation product where the entire value proposition is Catching problems before they compound, batch was never going to hold up. The complexity tax is the cost of the product actually doing what it claims to do.

Share this article

Back to Blog See Projects