Series · 7 parts Published July 4, 2026

Referral tracker

A happy customer who’d recommend you is the cheapest growth a small business has — and most shops have no way to turn that goodwill into anything they can actually track. This is the design of a small serverless system that gives every customer their own referral link on request: it mints a unique code, writes a shareable invite in the business’s voice, logs the click behind a redirect, attributes a sign-up to the referrer on a last-touch window, and — when the referred person actually converts — credits both sides exactly once and sends a thank-you. It blocks the obvious abuse: self-referrals, the same person converting twice, and codes sprayed into the void. Seven posts on the same system — one diagram at a time — with an engineering reference at the end.

  1. 01

    A referral tracker on AWS for a few dollars a month

    The whole system on one page — minting a unique referral link, logging the click behind a redirect, attributing a sign-up on a last-touch window, crediting both sides exactly once on conversion, and the fraud screen that blocks self-referrals, dupes, and codes shared into the void.

  2. 02

    How a referral link gets minted

    How a referral link is created — a customer asks, the system mints a unique short code, one Bedrock call writes a shareable invite in the business’s voice, and the code, the referrer, and the reward terms are recorded before the link ever goes out.

  3. 03

    How a referral gets attributed

    How a referral is attributed — the redirect that logs each click, the last-touch window that decides which referrer gets the credit at sign-up, and why a click and a sign-up alone earn nothing until a real conversion follows.

  4. 04

    How a reward gets issued

    How a reward is issued — the conversion webhook that confirms a genuine first purchase, the conditional write that pays both sides exactly once, and the single Bedrock call that writes the two thank-you notes while code does the actual crediting.

  5. 05

    How referral fraud gets caught

    How referral fraud is caught — self-referrals matched on identity, the same person converting twice collapsed to one reward, and velocity checks that hold a code spraying clicks or sign-ups for a human, all before anyone is paid.

  6. 06

    What the referral tracker costs

    A line-by-line monthly cost at about $1.70 — the cheapest system here — where the money actually goes (mostly a fixed Secrets Manager line, with redirects and writes rounding to cents), and what the bill looks like at ten times the volume.

  7. 07

    Engineering reference: the referral tracker architecture

    The same system drawn for engineers — the Lambda inventory, the redirect-and-webhook Function URL, the DynamoDB tables and key schema, how exactly-once crediting is enforced, the last-touch window and the expiry sweep, IAM scope, and the region.

What is a referral tracker?
It is a small serverless system that turns word-of-mouth into something a business can actually credit. A customer asks for a referral link; the system mints a unique code, writes a short shareable invite in the business’s voice, and hands it over. When a friend taps the link the click is logged behind a fast redirect; when that friend signs up, the sign-up is attributed to the referrer on a last-touch window; and when the friend converts — their first real purchase — the reward is issued to both sides exactly once and a thank-you goes out. Self-referrals, repeat conversions, and codes shared into the void are quietly filtered before anyone is paid.
How much does it cost to run?
About $1.70/month at a typical small-business volume — roughly 200 link clicks and 20 conversions. It is the cheapest system in this collection because the busy path is just redirects and tiny DynamoDB writes, with only a little SMS and a couple of small Bedrock calls. There is no always-on compute, so the bill is almost all usage-priced; the only real fixed cost is Secrets Manager for the provider keys. At ten times the volume the bill lands near $9, because the fixed lines don’t move.
Which AWS services does it use?
Lambda (Python 3.14, arm64) behind a single Function URL that serves both the link redirect and the sign-up and conversion webhooks, DynamoDB on-demand for codes, a click log, referrals and a rewards ledger, EventBridge Scheduler for the attribution-window expiry sweep, SNS for reward SMS and SES for invite, thank-you and fraud-review email, SQS with a dead-letter queue, Secrets Manager for the provider keys, CloudWatch Logs with 7-day retention, AWS Budgets, and Bedrock (Claude Haiku 4.5 via Global cross-Region inference) to write the invite and the thank-you notes. No API Gateway, no NAT Gateway, no always-on compute. One region, eu-west-2.
How fast does it act?
The redirect is instant — a click is logged and the visitor is sent on to your sign-up page in a few milliseconds, so the link feels like any other short link. Attribution happens the moment the friend signs up: the system looks back over the last-touch window (say 30 days) and credits the most recent referrer. The reward is held as pending until the referred person converts — a real first purchase — at which point both sides are credited within seconds and thanked. Nobody is paid on a click or a sign-up alone.
Does it use AI?
Only to write the words. Bedrock’s Claude Haiku 4.5 fires once when a link is minted, to compose a short shareable invite in the business’s voice, and once at conversion, to write the two thank-you notes. Every decision that matters — which referrer gets the credit, whether the last-touch window still applies, whether a conversion is a genuine first purchase, whether something smells like a self-referral or a bot — is deterministic Python. The model never decides who to credit, how much to pay, or whether a referral is real.
Can people game it?
That is most of the design. It credits each referred customer exactly once, to both sides, and only on a genuine conversion, so signing up ten times earns nothing. Self-referrals are caught by matching the referred person’s identity — account, payment fingerprint, device — against the referrer’s. Repeat conversions from the same person collapse to one reward by a conditional write. And a code that suddenly sprays clicks or sign-ups from one source trips a velocity check and is held for a human to look at rather than paid automatically. The honest majority never notice any of it.
All posts