When people sketch a payment gateway on a whiteboard, they usually draw one box called "backend" with arrows going to the chains. That works right up until you ask a simple question: if someone gets code execution in that box, what can they sign?
For a crypto gateway the answer matters more than usual. There's no bank to reverse a transfer, so the design has to make the dangerous thing hard before anything goes wrong, not after.
This is how we split Coldtill, the self-hosted gateway we build, and why the pieces talk through the database instead of to each other. The source is in the GitHub repo and the architecture page in the docs goes deeper, but the ideas carry over to any system that both faces the internet and moves money.
Split by blast radius, not by feature
Coldtill is one static Go binary with the React dashboard embedded. It runs as four processes:
| Process | What it does | Hot key? |
|---|---|---|
api |
Merchant API, dashboard, hosted checkout, conversion quotes | no |
watcher |
Chain watchers, confirmations and reorgs, payment expiry, webhook delivery | no |
sweeper |
Deploys deposit contracts when needed, sweeps deposits to cold wallets | yes |
payouts |
Signs, broadcasts, fee-bumps and confirms approved payouts | yes |
The line that matters is the last column. The one process the internet can reach, api, holds no private key. The two that do hold keys accept no network connections at all.
You could split the same code by feature: a "payments service", a "wallet service", a "notifications service". That's tidy, but each service ends up needing a port, and the wallet service ends up with an RPC method that says "send X to Y". Now the security of your money is the security of that method's auth check.
Splitting by "who can sign" gives you a cleaner rule: anything that listens doesn't sign, anything that signs doesn't listen.
The database is the only bus
The four processes share a PostgreSQL database and never call each other directly. No gRPC, no internal HTTP, no message broker.
That sounds old-fashioned, so here is why it fits this problem:
-
A compromised
apican only write rows. It can create a payment or a payout request, but a payout request is just a row. Thepayoutsprocess picks it up, checks it against limits and the address book, and holds it for approval if needed. There is no endpoint on the signing side to call with a forged argument. - Every intent is durable before it acts. A sweep is signed and stored before it's broadcast, then tracked until it's confirmed, replaced or failed. If the process dies between "signed" and "sent", the row is still there on restart.
- Restarts are boring. Each process reads its work from tables. You can restart the watcher during an upgrade and it carries on from the last processed block it stored for each network.
The cost is that you think in states instead of calls. A payment is a row with a status and amounts; deposits are rows with block numbers, confirmations and a status of pending, confirmed or orphaned. Every change queues a webhook delivery, which is also a row. Once you get used to it, debugging is mostly SELECT.
Two signers, one wallet: nonces under an advisory lock
Here's the part that bites anyone who has more than one thing sending from the same EVM address.
The sweeper and the payouts process can share an EVM hot wallet. Both need nonces, and if they each ask a node for "pending nonce" they'll eventually pick the same one, and one transaction silently replaces the other.
Coldtill reserves nonces under a Postgres advisory lock per wallet and network, inside the same transaction that stores the signed transaction. In sketch form:
BEGIN;
SELECT pg_advisory_xact_lock(hashtext(:wallet || ':' || :network));
-- read the next nonce for this wallet + network
-- sign the transaction with it
-- insert the signed tx row (and the nonce it used)
COMMIT; -- lock released here
Reservation and storage succeed or fail together, so you can't end up with a nonce handed out for a transaction that was never recorded.
The other edge case: a transaction fails permanently while a later nonce is already in flight. On EVM chains that later transaction will sit there forever, because the gap never fills. Coldtill fills it with a zero-value self-transfer so the queue can move. It's an ugly little transaction, and exactly the kind of thing that's easy to leave out until a queue gets stuck.
Don't trust one node for the scary decisions
The chain-facing processes talk to a pool of RPC nodes per network (Esplora for Bitcoin). The preferred node is tried first, a failing one is skipped for a cool-down, and a health loop probes all of them so the dashboard can show status and the last processed block.
For normal reads, one healthy node is enough. For decisions where being wrong costs money, such as "this payout never landed" or "this Bitcoin deposit was dropped", it asks every node. A single lagging or misbehaving provider shouldn't be able to make you resend a payout.
A small detail I like: node URLs are redacted in errors, since providers often put API keys in the URL. Logs get pasted into issues and chat, and you don't want your RPC key to go with them.
What this buys you, and what it doesn't
It doesn't make the server safe to ignore. The hot wallet that pays gas still lives on that machine, encrypted, and the processes that can unlock it are on that machine too. That's why the hot wallet is meant to hold small amounts, and why swept funds go to a cold wallet the server has no key for.
What it does buy is a narrower question. Instead of "is the whole backend secure?", you ask:
- Can anything reachable from the internet sign? (It shouldn't.)
- Can anything that signs be reached from the internet? (It shouldn't.)
- Is every action that moves money a stored row that a separate process checks before it acts? (It should be.)
If you're designing something similar, whether a payout system, a treasury tool or an internal wallet service, I'd start with those three questions before choosing a queue or an RPC framework. You might find you don't need either.
The full layout (internal/payment, internal/payout, internal/rpcpool, the Foundry contracts and the Solana program) is in the repo: https://github.com/Coldtill/self-hosted-crypto-payment-gateway

Top comments (1)
The database-as-bus design moves the trust question to one place: whoever can write a payout row can get it signed. So I'd look hardest at the DB roles. If the API role can only insert requests, and only a separate approval step can set them to approved, a SQL injection in the API can't move funds on its own.
Does the payouts process re-check each row against its own limits (per-address cap, destination allowlist) before signing, or does it trust the status column?