Database Strategy
Database choices follow the AWS infrastructure ADR (adr/servicos-serverless-aws.md).
| Entity | Database | Rationale |
|---|---|---|
| Lead, ChannelIdentity, LeadOrganization | Aurora PostgreSQL (via RDS Proxy) | Identity resolution requires JOINs, UNIQUE constraints, ACID |
| Event | DynamoDB | Append-only, high volume, key-based access |
| Memory | DynamoDB | Key-value with upsert, access by lead_organization_id |
| Feature | DynamoDB | Single item, single-digit ms reads |
DynamoDB Tables
event
memory
feature
Full Diagram
Ingestion Flow
Lambdas
Event Ingester
| Property | Value |
|---|---|
| Trigger | SQS: lead-ingestion |
| Reads from | Aurora (identity resolution via ChannelIdentity) |
| Writes to | DynamoDB (event), Aurora (creates lead/channel/lead_organization if new) |
| Publishes to | SNS: lead-events |
Memory Updater
| Property | Value |
|---|---|
| Trigger | SQS: memory-processing |
| Reads from | DynamoDB (memory, event) |
| Writes to | DynamoDB (memory) |
Feature Computer
| Property | Value |
|---|---|
| Trigger | SQS: feature-processing + EventBridge Scheduler |
| Reads from | DynamoDB (event, memory) |
| Writes to | DynamoDB (feature) |
SQS: feature-processing (near-realtime)
Triggered when a new event arrives via thelead-events SNS fan-out. Recalculates only the features affected by that specific event.
Example: a purchase_completed event arrives → recalculates monetary_total, frequency_purchases_90d, days_since_last_purchase, has_purchased. Other features (like sentiment_avg_30d) are not touched.
EventBridge Scheduler (periodic batch)
Some features change over time even without new events:| Feature | Why it changes without events |
|---|---|
recency_days | Yesterday it was 5, today it is 6. No event happened. |
days_since_last_purchase | Same — increments daily. |
campaign_ignored | If a lead received a campaign 7 days ago and never engaged, the system needs to detect this. |
sentiment_avg_30d | Old sentiment events fall out of the 30-day window. |
Summary
| Trigger | When it runs | What it recalculates |
|---|---|---|
| SQS feature-processing | When an event arrives | Features affected by that event |
| EventBridge Scheduler | Periodic cron (e.g., daily) | Features that depend on elapsed time |