Idempotency: why re-running a sync shouldn't double-bill
Idempotent describes an operation that has the same effect whether you do it once or ten times. Pressing an elevator's call button again does not summon a second elevator. Setting a status to “Paid” twice leaves it “Paid”. Creating an invoice, though, is not idempotent by default: do it twice and the client gets two invoices.
For any process that moves invoices from one system to another, idempotency is the difference between a sync you can safely re-run and one you are afraid to touch.
Why duplicates happen
Duplicate invoices are rarely caused by one big bug. They come from ordinary events:
- Retries. A request to create an invoice times out. The invoice was in fact created, but the reply never arrived, so the sender tries again.
- Re-triggers. An automation fires when a status changes to “Ready to bill”. Someone changes it back by mistake, then forward again. The automation fires twice.
- Double clicks and two people. Two people bill the same item on the same afternoon, or one person clicks a button twice.
- Edits after invoicing. An item is changed after its invoice was sent, and the next run treats it as new.
- Parallel runs. Two items for a new client are processed at the same moment, and each one creates the client, so the books end up with two customer records.
Techniques that prevent it
1. A stable reference back to the source
Give every invoice a reference to the board item it came from, and check for an existing invoice with that reference before creating a new one. If one exists, the run does nothing. This one check handles retries, re-triggers and double clicks. Done by hand, it is simply writing the invoice number back onto the item and refusing to bill items that already have one.
2. Versions instead of silent edits
Treat a changed item as a new version, not a new invoice. Compare the item's current lines with what was invoiced. If they differ, stop and ask a person whether to issue a credit note and a replacement, or to leave the invoice alone. Never overwrite a sent invoice quietly.
3. One at a time per account
Process the items for one accounting organization in sequence, not in parallel. It is slower by seconds and removes the race in which two items each create the same new customer. It also keeps you inside the accounting system's API limits.
4. A lock on customer creation
Before creating a customer, take a short lock on that customer's normalized email or name. A second process that wants the same customer waits, then finds the record the first one created.
5. A log of every attempt
Record each attempt with its reference and its result. When something does go wrong, the log shows whether an invoice was created, so nobody has to guess and nobody re-runs blindly.
Checking your current process
- If the same automation fired twice for one item right now, what would happen?
- Where is the invoice number recorded on the board, and does anything check it before billing?
- What happens to an item that is edited after it was invoiced?
If any answer is “I'm not sure”, the process is probably not idempotent yet.
How ColumnLedger is designed to handle it
ColumnLedger is planned to use all five techniques: a reference from each invoice to its board item, versions that require your confirmation, sequential processing per account, a lock on customer creation, and a sync log. That is a design goal for a product in early access, not a shipped guarantee. See how it is designed to work, or the full glossary.