EventBridge duplicate events causing processing errors

Seeing duplicate conversation:updated events in my EventBridge consumer. The id is identical but the timestamp differs by milliseconds. Is there a standard deduplication strategy or should I just key on the event ID in my Lambda?

Yeah, that millisecond drift is classic EventBridge behavior. It’s not actually duplicate data, just retries that got through because the timestamp shifted slightly. Keying on the event ID in Lambda is the right move, but you need to handle the state carefully so you don’t leak memory.

Here’s how I usually set up the dedup in the Lambda handler. You’ll need DynamoDB for the state store since Lambda is ephemeral.

const AWS = require('aws-sdk');
const dynamo = new AWS.DynamoDB.DocumentClient();

// Table name: event-dedup-cache
// Partition Key: eventId (String)

exports.handler = async (event) => {
 for (const record of event.Records) {
 const payload = JSON.parse(record.body);
 const eventId = payload.id; // This is the Genesys Cloud event ID

 // Check if we've seen this ID recently
 const getParams = {
 TableName: 'event-dedup-cache',
 Key: { eventId }
 };

 try {
 const result = await dynamo.get(getParams).promise();
 
 if (result.Item) {
 // Already processed, skip
 console.log(`Skipping duplicate event: ${eventId}`);
 continue;
 }
 } catch (err) {
 console.error('Error checking dedup table', err);
 // Decide if you want to fail or proceed on DB error
 }

 // Process your event here
 await processGenesysEvent(payload);

 // Mark as processed
 const putParams = {
 TableName: 'event-dedup-cache',
 Item: {
 eventId,
 timestamp: Date.now(),
 // Optional: TTL if you want to auto-cleanup old IDs
 // expiration: Math.floor(Date.now() / 1000) + (60 * 60 * 24) // 24 hours
 }
 };
 await dynamo.put(putParams).promise();
 }
};

Make sure your DynamoDB table has a TTL attribute if you go that route, otherwise it’ll grow forever. Also, check your EventBridge rule. If you’re using the genesyscloud source, ensure you haven’t got multiple rules firing off the same event bus pattern. Sometimes people create a generic # rule and then specific ones, causing double delivery at the infrastructure level before it even hits Lambda.

Check the EventBridge console under “Destinations” for your rule. Look at the “Invocations” vs “Successes”. If the ratio is off, you might be hitting a throttling issue that causes EventBridge to retry aggressively.