AWS Builder Center

Building a Daily Reconciliation Job for a Payments Ledger: Lambda + EventBridge Scheduler + DynamoDB

A serverless reconciliation pipeline that catches ledger drift between your system and a payment partner's records before it becomes unrecoverable — built with EventBridge Scheduler, Lambda, and DynamoDB, with working Python code and cost breakdown included.

If you're running any system that maintains its own ledger on top of a bank, payment processor, or lending partner, you have exactly one job that matters more than any feature you'll ship this quarter: catching drift between what your ledger says and what the partner's records actually show, before that gap compounds into something unreconcilable.
This isn't hypothetical. The most well-known recent case of this failing involved a fintech middleware provider whose internal ledger quietly diverged from what its partner banks actually held — by the time it collapsed, $265M across 100,000+ users was affected, and two years later the shortfall still hasn't been fully traced. That's the extreme case. The common case is smaller and quieter: a webhook processed twice, a refund that updated one system and not the other, a partial multi-step transaction that failed silently. Individually these are rounding errors. Left unchecked, they're not.
Here's a reconciliation architecture that catches this early, built entirely on managed AWS services — no always-on server, minimal cost, and simple enough to reason about at 2am when something's actually wrong.

Architecture

EventBridge Scheduler (daily cron)
│
▼
Lambda: reconcile-ledger
│
├──► DynamoDB: internal ledger (source of truth)
├──► Partner API / S3 export: external statement
│
▼
Diff engine (in-Lambda)
│
├──► match → write reconciliation-log entry (status: clean)
└──► mismatch → SNS topic → alert (PagerDuty/Slack/email)
The whole point of this design is that reconciliation isn't a step you run when something looks wrong — it's a scheduled, automated, boring job that runs whether anyone's watching or not.

DynamoDB table design

A single-table design works fine here. Partition key groups entries by account, sort key gives you a natural time-ordered history:
Table: LedgerEntries
PK: ACCOUNT#<account_id>
SK: TX#<iso_timestamp>#<tx_id>

Attributes:
amount (number, positive = credit, negative = debit)
tx_id (string, idempotency key)
status (string: posted | reconciled | flagged)
partner_ref (string, the partner's own transaction reference)
A GSI on  tx_id  lets you look up any entry by idempotency key in O(1) instead of scanning — this matters once you're reconciling tens of thousands of daily transactions.

The Lambda function

python
import boto3
import os
from decimal import Decimal
from datetime import datetime, timedelta

dynamodb = boto3.resource("dynamodb")
sns = boto3.client("sns")

ledger_table = dynamodb.Table(os.environ["LEDGER_TABLE"])
SNS_TOPIC_ARN = os.environ["ALERT_TOPIC_ARN"]
TOLERANCE = Decimal("0.01") # allow sub-cent rounding noise only

def handler(event, context):
yesterday = (datetime.utcnow() - timedelta(days=1)).date().isoformat()

internal_entries = get_internal_entries(yesterday)
partner_entries = get_partner_statement(yesterday)

internal_by_ref = {e["partner_ref"]: e for e in internal_entries}
partner_by_ref = {p["ref"]: p for p in partner_entries}

mismatches = []

# Entries in our ledger that don't match the partner's record
for ref, entry in internal_by_ref.items():
partner_entry = partner_by_ref.get(ref)
if partner_entry is None:
mismatches.append({"type": "missing_at_partner", "ref": ref, "amount": entry["amount"]})
continue
drift = abs(Decimal(entry["amount"]) - Decimal(partner_entry["amount"]))
if drift > TOLERANCE:
mismatches.append({
"type": "amount_mismatch", "ref": ref,
"internal": entry["amount"], "partner": partner_entry["amount"], "drift": str(drift)
})

# Entries the partner has that never made it into our ledger
for ref in partner_by_ref:
if ref not in internal_by_ref:
mismatches.append({"type": "missing_internally", "ref": ref, "amount": partner_by_ref[ref]["amount"]})

if mismatches:
alert(yesterday, mismatches)
return {"status": "flagged", "count": len(mismatches)}

return {"status": "clean", "date": yesterday}

def alert(date, mismatches):
sns.publish(
TopicArn=SNS_TOPIC_ARN,
Subject=f"Ledger reconciliation FLAGGED for {date}: {len(mismatches)} mismatch(es)",
Message=str(mismatches),
)

def get_internal_entries(date):
# Query DynamoDB via the tx_id/date-range GSI — implementation depends on your access pattern
...

def get_partner_statement(date):
# Fetch from partner API or pull a daily settlement file from S3
...
Two details worth calling out: this checks both directions (ours-missing-from-partner and partner-missing-from-ours), since drift almost never announces which side is wrong. And the tolerance is intentionally tiny — a cent, not a dollar — because "close enough" thresholds are exactly how real gaps hide inside acceptable noise for months.

Scheduling it

EventBridge Scheduler (not the older EventBridge rules cron, which still works but Scheduler is the more flexible current option) triggers this once a day, well after both systems' end-of-day batch processes have settled:
aws scheduler create-schedule \
--name daily-ledger-reconciliation \
--schedule-expression "cron(0 6 * * ? *)" \
--target '{"Arn":"arn:aws:lambda:...:function:reconcile-ledger","RoleArn":"..."}' \
--flexible-time-window '{"Mode":"OFF"}'

Cost

This is close to free at most transaction volumes. A single daily Lambda invocation, even processing tens of thousands of records within a 5-minute execution window, runs a few cents a month. DynamoDB on-demand pricing scales with your actual write volume from normal ledger operations — this job only adds read costs for the reconciliation query itself. The expensive part of drift was never the infrastructure to catch it; it's the cost of not having this running at all.

What this doesn't solve

This catches drift after both systems have written their records for the day — it won't catch a same-day double-charge before a customer notices. If you need that, the same diff logic can run as a near-real-time check on a DynamoDB Stream instead of a daily batch, at the cost of more complexity. Start with the daily job. Most teams that build the real-time version later wish they'd had even the daily version running six months earlier
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article