Library / Blogs

Asana Engineering Blog

Are you interested in learning more about working on Asana's engineering team or the work they do? Read the Asana engineering blog.

By Asana engineers · Asana · Added 2026-10-12

Open original source

All content belongs to Asana engineers / Asana. We only link to it and give credit. Report a problem

Learn this article

About 37 min left. Your work is saved as you go.

What you are about to study

Asana wrote this to explain how they thought about a problem. You should know the basics: caching, queues and replication.

Ideas you will meet

Distributed Systems
Consensus, time, failure and the fundamentals of scale-out.

What we already know about this

Our own lessons on these ideas. Read them here before you start, so it makes sense.

  • Core Concepts: How Things Actually Work · 9 minHow online payments workThe parties involved, why idempotency is essential, and how a ledger and reconciliation keep money correct.Read here

    The players

    A card payment involves several parties:

    • Customer and their issuing bank (which holds the account).
    • Merchant and their acquiring bank.
    • A card network (such as Visa or Mastercard) connecting banks.
    • A payment service provider (PSP) that handles the complexity for merchants.

    Most businesses do not touch card numbers: they use a PSP's hosted form or tokens, which shrinks security and compliance scope (PCI DSS).

    A card payment terminal at a shop checkout, the visible start of a long chain of banks and networksImage: Syced · CC0 · Source · Wikimedia Commons: LaCuCa card reader - payment terminal at supermarket register

    A typical flow

    Figure SDA-CORE-15-1 · A typical flow · © forcsguy.com

    Steps are usually authorise (reserve funds) then capture (take the money), then settlement between banks days later.

    Idempotency

    Networks time out, users double-click, services retry. Without protection, a retry can charge twice. Solve it with an idempotency key: a unique value per intended payment, sent with the request. The server stores the result under that key, and any repeat returns the stored result instead of acting again.

    Model the money as a ledger

    Never just update a balance field. Record every movement as entries in an append-only ledger using double-entry bookkeeping: each transaction has a debit and an equal credit.

    • Balances are computed from entries, and always sum to zero across the system, so errors stand out.
    • You get a full audit trail.
    • Use integer minor units (cents), never floating point, for amounts, and store the currency.

    State machines and asynchronous reality

    A payment moves through states: created, pending, authorised, captured, failed, refunded. Make transitions explicit and allow only valid ones. Many results arrive asynchronously by webhook, so your system must accept webhooks idempotently, verify their signatures, and tolerate them arriving late or out of order.

    Reconciliation

    Your records, the provider's and the bank's will occasionally disagree (a timeout hid a success, a webhook was lost). A scheduled reconciliation job compares them, flags mismatches and drives them to a resolution. Treat unexplained differences as incidents.

    Reliability and security

    • Keep the write path simple and durable; do slow work (emails, analytics) asynchronously.
    • Use strong consistency for balances and payment state.
    • Protect against fraud with limits, velocity checks and risk scoring.
    • Never log card data or secrets; use tokenisation and encryption.

    Real-world reading

    Open this lesson with its quiz and exercise

Go deeper on this

A path through videos, articles, other case studies and code on the same ideas as Asana Engineering Blog.

  1. Warm upGet the vocabulary first.

  2. WatchHow others solve the same problem, on video.

    Videos belong to their creators and play from YouTube. More on YouTube (opens in a new tab)

  3. ReadEngineers explain it in their own words.

  4. See it in another companyThe same ideas, a different system.

  5. Read the codeSee how it looks when it is real.

Keep learning

Loading community…