A payment is not one action. It is an authorisation, a ledger entry, a fraud check, a notification to the customer, a fee calculation, an update to the merchant's dashboard and, later, a settlement and a reconciliation. In many platforms all of that happens in one chain of synchronous calls, each waiting for the next. The chain works until a busy day. Then one slow service slows everything, a timeout leaves a payment half-processed, and nobody is sure whether to retry.
Event-driven architecture changes the shape of that chain. The service that does the work records what happened as an event, and the other services react to it in their own time. Done well, this makes a financial platform faster, easier to change and easier to audit. Done carelessly, it creates a new class of problems, and in fintech some of them cost money. This post covers both.
Events tell the system what happened
An event is a statement of fact in the past tense: a payment was authorised, a card was blocked, a payout was sent. It is published once, and any service that cares can subscribe to it. The publisher does not know or wait for its consumers.
That is different from a command, which asks a specific service to do something and expects an answer. "Charge this card" is a command. "The card was charged" is an event. Mixing the two up is the most common design mistake, and it produces systems where events are really hidden commands with nobody responsible for the result.
The benefits follow from the separation:
- Services scale and fail independently. A slow notification service no longer delays an authorisation.
- New features attach without touching old code. A new fraud model or analytics feed subscribes to existing events.
- The history is kept. An ordered log of business facts is the natural basis for audit, reconstruction and analysis.
- Busy periods are absorbed. Events queue up when consumers are behind, instead of turning into errors.
Keep money movements strictly consistent
The most important rule in fintech comes before any choice of broker. The ledger is not eventually consistent. Moving money between accounts, holding funds and recording a payment must happen as a single, strictly consistent operation, usually as a database transaction over double-entry records, where every debit has a matching credit.
Events then carry the news of that change to everything else: the customer's notification, the fraud model, the reporting store, the merchant's balance view. Those can be a few seconds behind without harm. The balance itself cannot.
Teams that spread a single money movement across several services joined by events end up rebuilding transactions by hand, badly. Draw the line deliberately: what must be correct at the moment of the write stays inside one transaction, and what may follow a moment later becomes an event.
Publish events reliably with an outbox
The first technical trap is the dual write. A service updates its database and then publishes an event. If it crashes between the two, the database says the payment happened and the rest of the system never hears of it. If it publishes first and the write fails, the system hears about a payment that did not happen.
The transactional outbox removes the gap. The service writes the business change and the event, into an outbox table, in the same database transaction. A separate relay reads the outbox and publishes to the broker, retrying until it succeeds. Either both are recorded or neither is.
For an older system that is hard to change, change data capture offers a route in: a tool reads the database's own change log and turns committed changes into events. It is a useful bridge, but the events it produces describe rows rather than business facts, so plan to translate them into proper domain events close to the source.
Ordering, partitions and hot accounts
Most event platforms guarantee order within a partition, not across the whole stream. In payments that matters: a refund processed before the charge it refunds is a bug that someone has to clean up.
The partition key decides what "in order" means. Keying by account or by payment keeps the events for each one in sequence while spreading the load across partitions. The cost appears with very active keys. A large merchant or a busy corporate account can push all its traffic into one partition while the rest sit idle. Watch the load per partition from the start, and for known heavy keys, decide in advance whether they need their own handling.
Where order matters across different keys, it is a sign that the logic belongs in one transaction or one service, not spread over several streams.
Process each event exactly once, in effect
Distributed systems deliver messages at least once. A consumer can process an event, crash before recording that it did, and receive it again. Exactly-once delivery across real networks is either expensive or narrower than it sounds. The dependable answer is to make every consumer idempotent: processing the same event twice must have the same effect as processing it once.
The usual techniques:
- Give every event a unique identifier when it is first recorded, in the outbox and in the same transaction as the change. Each consumer records the ones it has handled in the same transaction as the work they caused.
- Use the business key where one exists. A payout keyed by its instruction identifier cannot be created twice.
- Write conditionally, applying a change only if the record is still at the version the event expects.
- Send idempotency keys to outside systems such as card processors and banks, so a retried request is recognised as a repeat.
Where the key comes from matters as much as having one. A key built from anything that changes between attempts, such as a request identifier generated per call, a timestamp, a retry counter, the event's position in the stream or an identifier the relay assigns when it publishes, makes every retry look new. It passes code review and still pays twice. The key has to be fixed once, when the operation is first recorded, and carried unchanged through every retry, every consumer and every call to an outside system.
A duplicate event must never settle a payment twice. If a consumer cannot guarantee that, it is not ready for money.
Test it before you trust it. Replay a day of real events through each consumer in a staging environment, with personal data masked and emails and provider calls stubbed, then compare the ledger payment by payment rather than by totals, because errors can cancel out in a total. A clean day rarely contains the failures that matter, so add them on purpose: replay the same day twice, reorder the events of one account, and stop a consumer after it has done the work but before it has recorded it.
Retries and dead letters
Some events fail for reasons that pass: a timeout, a locked record, a provider that is briefly down. Others will fail every time, because the data is wrong or the code has a bug. Treating them the same way is how one bad message stops a whole stream.
- Retry with increasing delays for failures that may pass, with a limit.
- Move events that keep failing to a dead-letter stream, so the rest keep flowing.
- Alert on dead letters and own them. A dead-letter stream nobody reads is a slow data loss.
- Make reprocessing a supported operation, with a tool to fix and replay failed events after the cause is found.
Treat event schemas as contracts
Once several teams consume an event, its shape is a public contract. Renaming a field in one service can break three others that the author never heard of.
- Keep a schema for every event type, checked automatically when events are published, with a registry or an equivalent shared definition.
- Evolve compatibly. Add optional fields; do not remove or repurpose existing ones. A breaking change gets a new version and a period when both are published.
- Give each event type an owner, the team that publishes it and answers for its meaning.
- Keep payloads lean. Carry identifiers and the facts of the change, not a copy of the whole internal record. Large payloads are slow, and they leak internal design into every consumer.
- Name events in the language of the business: a payment was authorised, not a row was updated in a table.