All projects

Pick a Date

Invite someone on a date; they pick the time and what to do. No accounts: the link is the key.

The Pick a Date landing page on desktop and on a phone. Desktop view. Phone view.
letsgodate.love, the landing page

What it is

  • You offer a few times, and for each time the things you would be happy to do. The person you invite opens the link and picks one time and one plan.
  • Nobody needs an account. The link itself is the key to the invitation.
  • They answer one question at a time: what to do, then which day, then what time. Only combinations you actually offered ever appear.
  • You get an email as soon as the date is confirmed.

The problem

Without accounts, the link is the only thing that proves you were invited. It has to be impossible to guess, it should never sit anywhere it could leak from, and it must not end up in logs or a database dump.

An invitation also has to be answered exactly once. Two clicks, two tabs or a retry must not produce two confirmed dates, and the answer must always be one of the time and activity pairs that was actually offered.

How I built it

  • Built the API in Rust with Actix Web and SQLx on PostgreSQL, with a small surface: create an invitation, read it, respond to it, and send it by email.
  • Made each invitation link a 256-bit random token and stored only its SHA-256 hash, so a database leak does not hand out working links.
  • Let PostgreSQL enforce the rules, not just the code: constraints and composite foreign keys make an invalid or duplicate answer impossible to store, and triggers freeze an invitation once it exists, so what was offered can never change under the person reading it.
  • Sent emails that contain the link directly, and queued every other email in a retrying outbox inside the same transaction as the answer.
  • Required a Cloudflare Turnstile check on every write, and accepted it only if it was issued for this site, for that exact action, within the last ten minutes.
  • Kept the per-IP quotas in PostgreSQL, serialised with a transaction-scoped advisory lock, so they survive restarts and hold across replicas. A cheap in-memory limit sits in front of them, and the client IP is only read from X-Forwarded-For when the request came through a trusted proxy network.
  • Made the server refuse to start in production if Turnstile is switched off, the hashing pepper is too short, no trusted proxy networks are listed, or the mail sender settings are not the expected ones.
  • Recorded acceptance of the terms with the database clock, inside the same insert that creates the invitation, so there is no field a client could use to supply the time. A CHECK constraint stores the policy version and the timestamp together or not at all, and a trigger stops either from being changed later.
  • Built the frontend in React 19 and TypeScript with Mantine and Motion, built with Rsbuild and tested with Bun.

The interesting parts

Three independent guards against double booking

Responding to an invitation first locks its row with SELECT ... FOR UPDATE, looked up by the token hash, so two concurrent answers queue behind each other. The responses table has a UNIQUE constraint on the invitation, so even a code path that skipped the lock could not store a second answer. Finally, the invitation is marked answered with an UPDATE that only matches when responded_at is still empty, and the code checks that exactly one row changed. A composite foreign key also guarantees that the chosen activity was really offered for the chosen time slot. An integration test fires eight answers at one invitation at once against a real PostgreSQL and checks that exactly one wins.

A link that is never stored

Each token is 32 bytes from the operating system’s secure random generator, encoded as 43 characters of base64url. Only its SHA-256 digest is saved, and every lookup hashes the incoming token first. Anything that is not 43 base64url characters is rejected before it reaches the database. Values with little randomness, like IP addresses and emails, are instead hashed with a secret pepper, because a plain hash of an IP address can be reversed by trying them all.

The log line that leaked the link

The standard Actix tracing middleware records the raw request path in its root span, and because every log event carries the fields of its span, the invitation token ended up on every log line written during a request. I replaced it with my own middleware that opens the span with the token cut out of the path, a fixed route label for metrics and a request id. The token and every secret also print as <redacted> if anything ever formats them for debugging.

An email outbox that never holds the secret

A transactional outbox would normally store every email, but that would put working links in a database table. So the two emails that carry the link go out directly. The “date accepted” emails carry no token and are written to an email_outbox table in the same transaction as the response, so they are sent if and only if the answer was saved. The dispatcher claims one row at a time with FOR UPDATE SKIP LOCKED and a five-minute lease, so several API replicas could share the queue, and retries with quadratic backoff capped at an hour, up to eight attempts. It is also nudged as soon as an answer commits, instead of waiting for its next poll.

How it runs

  • Docker Compose with PostgreSQL, a one-shot migration service, the API, the web frontend and Varnish. No container publishes a port on the host; traffic reaches it only through an external proxy network.
  • Migrations are compiled into the API binary. A one-shot service runs the same image with a --migrate flag that needs nothing but the database URL, and the API does not start until it has exited cleanly.
  • The API runs as a non-root user, and every container has a hard memory limit with no swap.
  • Varnish answers 404 for /metrics, the web container’s health probe and source maps. It never caches anything under /api/v1/invitations, and any new API route stays uncached until someone writes a rule for it. Prometheus scrapes the API over a separate monitoring network.
  • GitLab CI runs rustfmt, clippy, unit tests and integration tests against a real PostgreSQL, checks that the image ships no Rust toolchain and does not run as root, then deploys images pinned to exact commits through an SSH key that can only run deploy or rollback.
  • A SQL test suite tries to insert invalid data directly and checks that the database rejects it, so the constraints are tested on their own, not only through the API.