We have a custom agent desktop component that listens for conversation events via AWS EventBridge. The integration is working, but we are seeing duplicate events arrive at the Lambda function. This is causing our screen pop logic to trigger twice for the same interaction.
The event payload looks like this:
{
"id": "abc-123-def",
"source": "genesys.cloud",
"detail-type": "conversation:participant:added",
"detail": {
"conversationId": "12345",
"participantId": "67890"
}
}
We are using the standard .NET Lambda template. The handler processes the event and updates the UI state. Since EventBridge can retry failed deliveries, duplicates happen. We need a deduplication strategy that is fast and does not block the main thread.
We tried storing the event ID in a local HashSet. It works for a while. But the Lambda container stays warm. The HashSet grows. Memory usage spikes. We need a better way.
Redis is an option. But adding a network call for every event adds latency. We want to keep the screen pop instant. Is there a pattern we are missing? Maybe a sliding window cache? Or should we just accept the duplicates and handle idempotency in the client app SDK?
Here is the current handler code:
public async Task FunctionHandler(CloudWatchEvent ev, ILambdaContext context)
{
var eventId = ev.Id;
if (_processedIds.Contains(eventId))
{
context.Logger.LogLine($"Skipping duplicate event: {eventId}");
return;
}
_processedIds.Add(eventId);
// Process event
await ProcessEvent(ev);
}
The _processedIds HashSet is static. It persists across invocations in the same container. This is the memory leak we are worried about. We need a cleanup mechanism. Or a different approach entirely. Any ideas on how to handle this efficiently in a serverless .NET environment?