DEV Community

Cover image for Day 80: Building an Event-Driven Bank Sync Pipeline (Webhooks, SQS & DynamoDB Locks)
Eric Rodríguez
Eric Rodríguez

Posted on

Day 80: Building an Event-Driven Bank Sync Pipeline (Webhooks, SQS & DynamoDB Locks)

When building fintech applications, letting the client dictate when to fetch third-party banking data will eventually destroy your API rate limits and skyrocket your cloud bill.

Today, I tore down my reactive data-fetching logic and replaced it with a resilient, event-driven webhook architecture using AWS Lambda, Amazon SQS, and DynamoDB. Here is how I solved the core architectural bottlenecks in my Serverless Financial Agent.

Fixing the Stale Dashboard & Identity Resolution
My React dashboard was showing stale data, while the daily automated emails had real-time numbers. The root cause? An identity partition mismatch. The background worker was using a default ID, while the frontend sometimes resolved to an email address instead of the strict Cognito sub ID. I unified the identity resolution algorithm so both endpoints read and write to the exact same DynamoDB partition.

Event-Driven Sync Pipeline
I deprecated the dangerous user-triggered "Force Sync" pattern. Instead, I implemented a persistent Plaid Access Token and shifted to a Webhook-to-SQS pipeline.
Now, when a transaction is added, modified, or removed, the Plaid API fires a webhook to my Lambda. To avoid timeouts, the Lambda instantly pushes a sync_transactions task to an SQS queue (FinanceAgent-SyncQueue) and returns a fast 202 Accepted back to the bank.

Cursor-Based Sync & DynamoDB Locks
The background SQS worker processes the event using a new /transactions/sync logic with a persistent cursor, fetching only the exact delta of changes. If the cursor fails, it gracefully falls back to the standard /transactions/get method.
To prevent API abuse, I built atomic sync locks in DynamoDB. If a sync is already running, the request is safely ignored. I also added strict routing logic to protect my live Wise profile from this Plaid-specific reactive sync behavior.

Curing AI Hallucinations
Finally, I patched the semantic AI layer. The system was treating credit card refunds and cashbacks as actual "Income," artificially inflating the user's AI Financial Health Score. I updated the classification engine to isolate real income (payroll, Gusto, interest) from simple cashflow corrections, ensuring the AI context is 100% accurate.

Verification & Next Steps
I verified the backend with Python compile checks, confirmed Lambda deploys (LastUpdateStatus=Successful), and validated the webhook endpoints. Next up: replacing the Sandbox Link flow with real production access tokens.

Top comments (0)