
How to Track CRM Lead Status History with AWS Lambda and DynamoDB
Build a CRM lead status history with AWS Lambda and DynamoDB. Track who changed each stage, calculate time spent in stages, and handle retries, corrections, and late events.
Series: CRM (9 articles)
- …
- 8How to Track CRM Lead Status History with AWS Lambda and DynamoDB This article
A CRM lead status history records each stage change with the previous stage, new stage, time, actor, and reason. Keep the current stage available for the sales queue and save a separate event for each accepted change. On AWS, Lambda can apply the transition rules and a DynamoDB transaction can update the current record and insert its history event together.
Why does the current lead status leave gaps in reporting?
Imagine a website enquiry that takes two days to qualify. The CRM shows
QUALIFIED today. Marketing wants to know whether the lead waited two days for the first reply or whether sales contacted them quickly and needed two days to confirm the requirement.The current stage cannot tell you where that time went. A stage history shows when each handoff happened. It also lets a manager find enquiries that repeatedly return to review because a qualification criterion is unclear.
Consider an illustrative lead:
Time | Event | Reporting implication |
|---|---|---|
Monday 09:00 | Enquiry saved as NEW | Start the intake clock |
Monday 09:20 | First human response, stage moves to CONTACTED | 20 minutes in NEW |
Monday 15:00 | Sales changes stage to QUALIFIED | 5 hours and 40 minutes in CONTACTED |
Wednesday 11:30 | Sales moves it to NURTURE after the buyer postpones | Record why the stage changed |
Friday 10:00 | Buyer confirms a new start date and sales qualifies the lead again | Start a second QUALIFIED interval |
Save both entries into
QUALIFIED . Sales may want to measure the first qualification for a funnel report and the total time in qualification for a workflow report.What fields belong in a stage change event?
Keep the event small enough to review and export easily. A typical record includes:
- Lead and workspace identifiers to scope the event and its current record.
- Previous and new stage to show the transition.
- Event ID and revision to identify an accepted operation and order the history.
- Occurred time and recorded time to show when the activity happened and when the system learned about it.
- Actor and source to distinguish a rep’s decision from an integration update.
- Reason code, such as
REQUIREMENT_CONFIRMED,TIMELINE_DEFERRED, orSTAGE_CORRECTION.
Store call notes and prospect messages in the system designated for those records. Keep the activity event focused on the facts necessary to explain the change.
{ "workspaceId": "demo-sales", "leadId": "lead-208", "eventId": "change-104", "revision": 3, "previousStage": "CONTACTED", "newStage": "QUALIFIED", "occurredAt": "2026-11-16T15:00:00Z", "recordedAt": "2026-11-16T15:00:02Z", "source": "SALES_PORTAL", "actorRef": "rep-17", "reasonCode": "REQUIREMENT_CONFIRMED"}How do you keep the current stage and history in sync?
Use one DynamoDB transaction for related items. One item holds the current stage. Another stores the new history entry. A third can map the operation ID to the accepted result for safe retries.
Update current lead Require stage = CONTACTED and revision = 2 Set stage = QUALIFIED and revision = 3
Insert stage history event Require the event key for revision 3 to be new
Insert operation result Require operation ID change-104 to be newIf two requests try to change revision 2 at once, only one can advance it to revision 3. The other can reload the current state and show the user that another update landed first. If the browser times out after a successful write, look up the operation ID and return the result when the original inputs match.
Define which transitions are permitted. For example, a rep may move
QUALIFIED to NURTURE when a project is postponed, while closing a lead may require a reason. Record corrections as new events so a manager can see how the record changed.How should you handle a late CRM event?
A CRM may send the same event again after a timeout. It can also deliver an earlier change after a newer one. Decide which system owns pipeline stage and use its stable event identifiers and revisions where available.
- Duplicate event. Reuse the source event ID and confirm whether it was already processed.
- Older event. Retain or review it under your history policy. Preserve the newer current stage.
- Skipped revision. Retrieve the missing history or check the authoritative record before assuming the sequence is complete.
- Conflicting source. Follow the agreed field ownership policy and surface the mismatch for review.
An occurrence timestamp is good for reporting. A reliable source revision is usually a better basis for deciding whether an inbound event should replace current state. Keep both when the integration provides them.
Turn the history into a sales report
For an individual lead, read the events in order and calculate the elapsed time between consecutive stage changes. For a reporting cohort, export the allowed fields to Amazon S3 and calculate stage intervals in Athena. For every stage entry, use the time of the next accepted transition as its end. Report an open stage through a fixed reporting cutoff.
If a lead returns to the same stage, decide whether the report needs its first entry, latest entry, or total time across all visits. Those are three valid measures with different uses.
Metric | Question it answers |
|---|---|
Median time in NEW | How long do enquiries typically wait for the first stage change? |
Percentile time in CONTACTED | Which leads take unusually long to qualify or exit the stage? |
First qualification rate by campaign | Which acquisition cohorts produce enquiries that qualify at least once? |
Reopened or repeated stage count | Where does sales return to the same step? |
Unresolved stage conflicts | How often do connected systems disagree about the current record? |
Before comparing campaigns, give each cohort the same observation window. A campaign that launched yesterday will have fewer opportunities to qualify than one whose enquiries have been under review for a week.
Test the edge cases sales will notice
- Submit two different transitions from the same lead revision. Confirm one is accepted and the other sees the new state.
- Retry a successful stage change with the same operation ID. Confirm the history still contains one accepted event.
- Deliver an older CRM event after a newer assignment. Confirm the old event leaves the current stage intact.
- Move a lead back to a previous stage and qualify it again. Confirm the report shows two separate intervals.
- Correct an erroneous stage with an authorized operation. Confirm the history shows the original entry and correction.
- Compare the sales dashboard with a handful of individual lead histories before sharing the aggregate report.
Frequently asked questions
Can I use the CRM’s last modified date to measure stage duration?
Use stage-specific events where possible. A last modified date may change when someone edits a phone number, owner, or note, even if the stage stays the same.
Should I track sales activity separately from stage changes?
Yes. A call attempt or meeting can be useful without changing the stage. Keeping activity distinct lets the team define metrics such as first human response independently.
How do I represent a lead that’s still in one stage?
Keep the stage interval open and calculate its age through the report’s cutoff. Include open records when reviewing backlog and label them separately from completed intervals.
What if I already have months of CRM data with only a current stage field?
Start collecting stage events from a known cutover date. Import trustworthy historical events where available, and mark earlier intervals as unknown when the underlying timestamps are missing.
Series: CRM (9 articles)
- …
- 8How to Track CRM Lead Status History with AWS Lambda and DynamoDB This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article