DEV Community

Cover image for Day 78: Fixing "Ghost Data" and Escaping the Spam Folder
Eric Rodríguez
Eric Rodríguez

Posted on

Day 78: Fixing "Ghost Data" and Escaping the Spam Folder

When building serverless apps, your frontend is often faster than your database's replication speed. 🏃‍♂️💨

The Problem: My AI Agent was suffering from "Ghost Data". After a user updated their profile, the AI would still use the old data for its analysis.
The Cause: Eventual Consistency. DynamoDB was still syncing the new name across nodes while the frontend was already asking for a response.

The Fix (React + Python):
I implemented a tactical 1.5s delay in the UI during the "Provisioning" state to give the cloud time to settle. On the backend, I modified the cache key generation:

Python

Before: Only used transactions for the cache key

cache_key = generate_cache_key(items, income, expenses, tone, user_id)

After: Included display_name to force a cache break on name changes

cache_key = generate_cache_key(items, income, expenses, f"{tone}_{display_name}", user_id)
Infrastructure Hardening (SES + Route 53):
To fix Spam issues in Yahoo, I moved the DNS to Route 53 and published:

Custom MAIL FROM: mail.duromoney.com to achieve SPF alignment.

DMARC Record: v=DMARC1; p=none; to pass mandatory security checks.

IAM Permissions: Injected AdminDeleteUser to the Lambda role so it can delete Cognito identities, not just database rows.

Code for the logic, but architect for the distributed reality! 🏗️⚡

Top comments (0)