Automation

Duplicate webhook deliveries

Keep the first delivery of each incident event so repeated webhook delivery does not duplicate notifications.

In production

Duplicate deliveries inflate metrics and fan-out. Sorting them rewrites history; dropping the first delivery loses the real event.

What it must return

Keep the first record for each event id and preserve first-delivery order.

  • Each event has a string id and arbitrary JSON fields. Return complete first-seen records in input order. Later copies of an id are ignored even if their payload differs.
  • Do not mutate input values. Use the Python standard library only.

Edge cases

  • Track seen ids separately from the output list.
  • Do not sort by id or timestamp unless the contract says so.
  • Later duplicates are dropped entirely.

Signature

unique_events(events)

Hints

  1. Second hint

  2. A partial sketch

The reference solution opens after the last hint.

solution.py · Python

Loading editor…

Repeated delivery

events

[
  {
    "id": "a",
    "state": "open"
  },
  {
    "id": "a",
    "state": "closed"
  },
  {
    "id": "b",
    "state": "open"
  }
]

Expected

[
  {
    "id": "a",
    "state": "open"
  },
  {
    "id": "b",
    "state": "open"
  }
]

Each run uses a fresh Python runtime in this browser, with a 3-second limit and a Stop button. The first run downloads the runtime. 0 of 8 in Automation passed in Python on this device.

Next: Keys on shards