Step 3: ID-Based Deduplication for Unique Identifiers
When the producer contract defines a stable unique identifier, ID-based deduplication can use that value directly as the cache key.
This pattern skips the need for hashing content and instead uses the event's own ID as the unique key.
The Goal
This configuration uses event_id directly rather than calculating a content hash.
Implementation
-
Start with the Previous Pipeline: Copy the
fingerprint-dedup.yamlfrom Step 2 to a new file namedid-dedup.yaml.cp fingerprint-dedup.yaml id-dedup.yaml -
Simplify the Key Creation: Open
id-dedup.yaml. You will replace the complex fingerprintingmappingprocessor with a much simpler one that just uses theevent_id.Replace the first 'mapping' processor in id-dedup.yaml# This processor is now much simpler.
- mapping: |
root = this
# The key for deduplication is now just the event's own ID.
root.dedup_key = this.event_idInside the inherited
for_each, replace the lookup branch so it checksdedup_keyand preserves the record.Replace the lookup branch- branch:
request_map: root = this.dedup_key
processors:
- cache:
resource: dedup_cache
operator: exists
key: '${!content()}'
result_map: root.is_duplicate = content().string().bool()Inside the same
for_each, replace the conditional cache write to storededup_key. Keep the final duplicate-filteringmappingprocessor from Step 1 there as well.Replace the conditional cache write- switch:
- check: '!this.is_duplicate'
processors:
- cache:
resource: dedup_cache
operator: set
key: '${!this.dedup_key}'
value: seen -
Deploy and Test:
# --- Send the SAME event twice ---
curl -X POST http://localhost:8080/ingest \
-H "Content-Type: application/json" \
-d '{"event_id": "abc-123", "message": "hello"}'
curl -X POST http://localhost:8080/ingest \
-H "Content-Type: application/json" \
-d '{"event_id": "abc-123", "message": "hello again"}' -
Verify: Check your logs. Even though the
messagewas different in the second request, it was dropped as a duplicate because it had the sameevent_id. This method is extremely fast and efficient when you can rely on a unique identifier in your events.