How to write idempotent event handlers

TODO.