Nov 20, 20266 min read

Build a Wire Transfer Approval Backend with Maker-Checker Rules

Build the approval workflow behind outgoing wires: a maker creates the request, one or more checkers approve it under dual-control rules, limits decide how many approvals are needed, every step is recorded, and an approved wire is released once. In Go on Postgres.

Illustration for Build a Wire Transfer Approval Backend with Maker-Checker Rules

Moving money out of an account is the one action a payments backend must never let a single person take alone. Banks and fintechs split it in two, so one person prepares the wire and another approves it, with more approvals as the amount grows.

The rule is easy to state and easy to get subtly wrong, with approvals counted twice, makers approving their own requests or a wire released twice. This guide builds the workflow in Go on Postgres.

What does a wire approval workflow need?

ConceptRule
MakerCreates the request, cannot approve it
CheckerApproves or rejects, each checker counts once
ThresholdAmount decides how many approvers are required
Statepending, approved, rejected, released
AuditEvery action recorded with actor and time
ReleaseHappens exactly once after the last approval

Dual control is a long-standing practice in payment operations, and the details are defined by each institution's policy. The Federal Reserve's wire service overview describes the settlement side, while approval rules belong to your own policy and your bank's requirements.

How should the schema enforce the rules?

Put as much as possible in constraints, because constraints hold when application code has a bug. A wires table carries the amount, beneficiary and maker. An approvals table has UNIQUE (wire_id, approver) so the same person cannot approve twice, and a CHECK on wires.status limits the states. Whether the approver differs from the maker is checked in the approval transaction, since it compares two tables.

Store thresholds in a small table, such as approval_rules (min_amount_cents, required_approvals), and look up the highest rule that applies to the amount. Compliance can then change the policy with a data change and a record of who changed it.

How do you count approvals safely?

Two checkers approving at the same moment can each see one approval and neither release, or both see two and both release. Lock the wire row with SELECT ... FOR UPDATE at the start of the approval transaction, insert the approval, count distinct approvers, and if the required number is reached move the status to approved in the same transaction. Locked this way, the transition happens exactly once. The locking trade-offs are covered in optimistic vs pessimistic locking.

Lock the amount at creation: if a request is edited after approvals arrive, discard the approvals and start again.

How do you release the wire once?

The approved state is the trigger: publish a single message with the wire ID after commit, and let a subscriber submit it to the bank using the wire ID as the idempotency reference, then mark it released. A redelivered message finds the wire already released and does nothing. Use the transactional outbox if losing the publish after commit is not acceptable.

What should the audit trail record?

Every action: created, approved, rejected, edited, released, with actor, time and the rule that applied. Make the table append-only, with no updates or deletes granted to the application role, and keep it as long as your regulator requires. The trail answers who approved a wire and under which threshold, long after the people involved have moved on.

Building it with Encore

Encore

Encore is a backend framework with built-in infrastructure. The service declares its Postgres database and a Pub/Sub topic for released wires in Go, and Encore provisions them on AWS or GCP in your own account on deploy, with encore run starting both locally.

Set up the app

Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

-- wires/migrations/1_create_tables.up.sql CREATE TABLE wires ( id BIGSERIAL PRIMARY KEY, maker TEXT NOT NULL, amount_cents BIGINT NOT NULL CHECK (amount_cents > 0), beneficiary TEXT NOT NULL, status TEXT NOT NULL DEFAULT 'pending' CHECK (status IN ('pending', 'approved', 'rejected', 'released')), created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE TABLE approvals ( wire_id BIGINT NOT NULL REFERENCES wires(id), approver TEXT NOT NULL, at TIMESTAMPTZ NOT NULL DEFAULT now(), UNIQUE (wire_id, approver) ); CREATE TABLE wire_events ( id BIGSERIAL PRIMARY KEY, wire_id BIGINT NOT NULL REFERENCES wires(id), actor TEXT NOT NULL, action TEXT NOT NULL, at TIMESTAMPTZ NOT NULL DEFAULT now() );
// wires/wires.go package wires import ( "context" "errors" "encore.dev/beta/auth" "encore.dev/beta/errs" "encore.dev/pubsub" "encore.dev/rlog" "encore.dev/storage/sqldb" ) var db = sqldb.NewDatabase("wires", sqldb.DatabaseConfig{Migrations: "./migrations"}) type Released struct { WireID int64 `json:"wire_id"` } var ReleasedTopic = pubsub.NewTopic[*Released]("wire-released", pubsub.TopicConfig{ DeliveryGuarantee: pubsub.AtLeastOnce, }) // requiredApprovals is a policy example. Load it from a table in a real system. func requiredApprovals(amountCents int64) int { switch { case amountCents >= 100_000_00: return 3 case amountCents >= 10_000_00: return 2 default: return 1 } } type ApproveResponse struct { Status string `json:"status"` } //encore:api auth method=POST path=/wires/:wireID/approve func Approve(ctx context.Context, wireID int64) (*ApproveResponse, error) { uid, _ := auth.UserID() approver := string(uid) tx, err := db.Begin(ctx) if err != nil { return nil, err } defer tx.Rollback() var maker, status string var amount int64 err = tx.QueryRow(ctx, `SELECT maker, status, amount_cents FROM wires WHERE id = $1 FOR UPDATE`, wireID). Scan(&maker, &status, &amount) if errors.Is(err, sqldb.ErrNoRows) { return nil, &errs.Error{Code: errs.NotFound, Message: "wire not found"} } else if err != nil { return nil, err } if status != "pending" { return nil, &errs.Error{Code: errs.FailedPrecondition, Message: "wire is not pending"} } if approver == maker { return nil, &errs.Error{Code: errs.PermissionDenied, Message: "the maker cannot approve"} } // A second approval by the same person violates the unique constraint and is ignored. if _, err := tx.Exec(ctx, `INSERT INTO approvals (wire_id, approver) VALUES ($1, $2) ON CONFLICT DO NOTHING`, wireID, approver); err != nil { return nil, err } if _, err := tx.Exec(ctx, `INSERT INTO wire_events (wire_id, actor, action) VALUES ($1, $2, 'approved')`, wireID, approver); err != nil { return nil, err } var count int if err := tx.QueryRow(ctx, `SELECT count(*) FROM approvals WHERE wire_id = $1`, wireID).Scan(&count); err != nil { return nil, err } newStatus := "pending" if count >= requiredApprovals(amount) { newStatus = "approved" if _, err := tx.Exec(ctx, `UPDATE wires SET status = 'approved' WHERE id = $1`, wireID); err != nil { return nil, err } } if err := tx.Commit(); err != nil { return nil, err } if newStatus == "approved" { if _, err := ReleasedTopic.Publish(ctx, &Released{WireID: wireID}); err != nil { return nil, err } } return &ApproveResponse{Status: newStatus}, nil } var _ = pubsub.NewSubscription(ReleasedTopic, "submit-to-bank", pubsub.SubscriptionConfig[*Released]{ Handler: func(ctx context.Context, r *Released) error { // Only the first delivery moves approved to released. res, err := db.Exec(ctx, `UPDATE wires SET status = 'released' WHERE id = $1 AND status = 'approved'`, r.WireID) if err != nil { return err } if res.RowsAffected() == 0 { return nil } rlog.Info("submitting wire", "wire_id", r.WireID) // Submit to the bank here using the wire ID as the reference. return nil }, })

The row lock serializes concurrent approvals, ON CONFLICT DO NOTHING absorbs repeat clicks, UNIQUE (wire_id, approver) stops double counting, and the maker check compares the authenticated user with the stored maker. The Encore auth handler provides the user ID, so an approver cannot be spoofed from the request body. Publishing after commit can lose the message if the process dies in between, so a production system should use the outbox pattern, or run a periodic sweep for wires stuck in approved.

A coding agent can add a new threshold or a role check in the same change as its test, run the approval flow with several users locally, and ship it with the database and topic provisioned from the code.

Best fit: Fintech teams in Go building payment operations tooling who want approval rules enforced in Postgres and release steps on Pub/Sub in their own AWS or GCP account.

Frequently asked questions

What is the maker-checker principle?

The maker-checker principle, also called the four-eyes principle or dual control, requires that the person who creates a sensitive transaction is not the person who approves it. For payments it prevents one compromised or mistaken user from moving money alone.

How do you enforce maker-checker in a database?

Store each approval as a row with a unique constraint on the request and approver, and check in the approval transaction that the approver is not the maker. Count distinct approvers against the threshold for the amount, and release only when the count is reached, inside the same locked transaction.

How many approvals should a wire need?

It depends on the amount and risk policy. A common scheme is one approver below a threshold, two above it and an extra role for the largest amounts, with the thresholds stored as configuration so compliance can change them without a deploy.

How do I build a wire approval backend with Encore?

A Go service declares the Postgres database and a Pub/Sub topic for released wires. Approval rules run in a locked transaction, and the release publishes one message to the topic that a subscriber sends to the bank. Encore provisions the database and topic in your own AWS or GCP account on deploy.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders