Projects1 of 7

Linkify

Short links, QR codes and click analytics, built so that measuring a click never slows the redirect down.

Linkify’s homepage: “Share the right thing. Learn what lands.” beside a card for creating a short link.
SkyloomThreadfern

Paste a URL, get a short one, share it, and see what happened to it. Linkify exists in two versions. The one live at uselinkify.com runs on Cloudflare Workers, with a Java core for large-file sharing. The second is a rewrite of the core in Java 21 and Spring Boot 4, where I worked through the redirect path, the analytics pipeline and the security properly. The rewrite is tested end to end but not deployed yet, and this page is clear about which version does what.

244
tests in the Spring Boot rewrite, with Postgres and Redis run for real in Testcontainers
60 s
how long a missing short code is cached, so scans for codes don’t reach the database
1 GB
largest file the live site uploads, in 16 MiB parts straight to S3
0
IP addresses stored. Unique visitors come from a daily-rotating hash
Next: Two versions, one product

Two versions, one product

  • Live at uselinkify.com: Next.js on Cloudflare Workers, D1 with Drizzle, Supabase Auth, and an optional Java 17 Spring Boot core that handles S3 multipart uploads, passcodes, click limits, activation dates, CSV import and profile pages.
  • The rewrite: a modular Spring Boot 4.1 monolith on Java 21, organised by feature (auth, link, redirect, analytics, abuse) rather than by layer, with PostgreSQL 17 as the source of truth and Redis 7.4 for the redirect cache and rate limits. Accounts, links, cached redirects, analytics, QR codes, rate limiting, anonymous links and password reset all work; it just isn’t deployed yet.
  • A modular monolith, not microservices: every module shares one database and one deployment, and splitting them would add network calls and distributed transactions to buy independence nothing needs yet.
Next: The redirect path

The redirect path

A redirect is the request people actually feel, so it does as little as possible. It checks Redis, falls back to a six-column Postgres projection with no joins, answers with a 302, and hands the click to a background worker. Pick a case below to see the path it takes.

How Linkify resolves a short link

GET /launch

  1. Redis GEThit
  2. Check expirystill live
  3. Respond302 to the destination
  4. Record the clickon a background worker

Most clicks look like this: one Redis read and an expiry check. The click is handed to a bounded background worker, so the visitor never waits for analytics.

GET /zz9x

  1. Redis GETmiss
  2. PostgreSQL lookupnot found
  3. Cache the missfor 60 seconds
  4. Respondnot-found page

Bots scan for codes that don’t exist. Caching the miss for a minute turns a burst of probes into one database query instead of thousands.

GET /spring-sale

  1. Redis GEThit
  2. Check expiryexpired
  3. Responda page that explains the link expired

The cached entry carries the link’s expiry, and it is checked on every hit. A stale cache can never keep an expired link alive.

GET /launch

  1. Redis GETerror, counted
  2. PostgreSQL lookupfound
  3. Respond302 to the destination

A cache failure is not a site failure. The resolver falls back to PostgreSQL. The instance reports itself not ready, so the load balancer drains it, but stays live, so it isn’t restarted into a storm.

Bars show the order of the work, not measured timings.

  • Hits are cached for an hour, capped at the link’s own expiry, and the expiry is re-checked on every hit, so a stale cache can never keep an expired link alive.
  • The cache entry is evicted after the transaction commits, so a read racing an edit can’t put the old row back. Title-only edits don’t evict at all.
  • Any Redis error counts as a miss. The instance reports itself not ready, so the load balancer drains it, but stays live, so a cache blip doesn’t become a restart storm.
  • 302, not 301: a permanent redirect is cached by browsers forever, so edits, disabled links and repeat clicks would all become invisible.
Next: Analytics that can’t slow a click

Analytics that can’t slow a click

Recording a click on the request threadParsing the user agent, classifying the referrer and writing two rows on every redirect would make the visitor wait for analytics.

The handler only builds a small event. A bounded executor (2 to 4 threads, a 1,000-item queue) does the rest, and when the queue is full the event is dropped and counted rather than pushed back onto the request.

A transaction that silently wasn’t oneSpring’s @Transactional does nothing when a bean calls its own method, so the click write ran without a transaction.

The database write moved into its own ClickWriter bean, so Spring’s proxy wraps it.

Counting people without tracking themUnique visitors need to tell two visitors apart, not know who they are.

The stored value is a SHA-256 of a per-process secret, the UTC date, the IP and the user agent. Because the date is in the hash, the same person hashes differently tomorrow, so the metric is honestly “unique per day”. Country comes from CDN headers, not a GeoIP lookup.

Next: Short codes and the race for a custom slug

Short codes and the race for a custom slug

  • Generated codes are 7 random Base62 characters from SecureRandom: 62⁷ is about 3.5 trillion codes, enough for roughly 111 years at 1,000 links a second.
  • A collision is retried up to five times, each attempt in its own REQUIRES_NEW transaction, because a failed INSERT poisons the JPA session it ran in.
  • Two people claiming the same custom slug at once are settled by a UNIQUE index: one wins, the other gets a 409. A test fires both claims behind a latch and repeats five times.
  • Postgres char(n) and citext both failed Hibernate’s schema validation, so both became varchar with a CHECK constraint.
Next: Accounts and security

Accounts and security

Each rate limit chooses how it fails when Redis is down
ActionLimitIf Redis fails
Anonymous link5 an hourRefuse: it’s the one open write
Password reset request3 an hourRefuse
Log in20 per 15 minutesAllow
Register5 an hourAllow
Redeem reset link10 per 15 minutesAllow
  • Passwords use Argon2id at 19 MiB, two passes. I rejected 64 MiB: twenty concurrent logins would need about 1.3 GB, enough for an attacker to knock over a 512 MB container. Unknown emails are checked against a dummy hash so response time doesn’t reveal which accounts exist.
  • The access token lives only in memory. The 30-day refresh token is stored hashed, sent in an HttpOnly SameSite=Strict cookie, rotated on every use, and replaying a used one revokes the whole session family.
  • A Next.js route acts as a same-origin proxy, which keeps that cookie strict and avoids CORS entirely.
  • The API never fetches the URLs people shorten, so there is no server-side request forgery to defend. Destinations are parsed, not prefix-matched, and javascript:, data: and file: are refused.
Next: Large files on the live site

Large files on the live site

  • Uploads go straight from the browser to S3 in 16 MiB parts, up to 1 GB, so the server never carries the file.
  • Each part URL is signed for 15 minutes and each download URL for 5. The part list and ETags are checked before an upload completes, and failed uploads are aborted so no half-files linger.
  • Moving data from D1 into Postgres runs as a single, restart-safe transaction, and old salted SHA-256 passcodes are upgraded to bcrypt the first time someone enters them correctly.
Next: How it’s tested

How it’s tested

  • 244 tests in the rewrite, with no failures or skips. Integration tests run against real PostgreSQL 17 and Redis 7.4 through Testcontainers, because an in-memory database would let SQL mistakes through.
  • One suite runs with no Redis at all, which is harsher than a real outage. Another proves that replaying a used refresh token revokes every session in its family.
  • The live version has 54 Node tests and 14 JUnit tests in CI, plus a manual browser checklist.
Next: Limits and next

Limits and next

Where it falls short

  • The rewrite isn’t deployed, and no performance numbers have been measured for it yet, so none are claimed.
  • The rewrite has no email provider: in development the reset link is logged, elsewhere the mailer returns 503.
  • Access tokens can’t be revoked before they expire; a 15-minute lifetime is the mitigation.

What’s next

  • Deploy the rewrite and move the live site onto it.
  • Password-protected and one-time links, custom domains and file sharing in the rewrite.
  • A k6 load test comparing redirects with and without Redis, then Terraform for AWS.
Next: Built with

Built with

Interface

Services

Data

Delivery

Testing

Bigger tiles are tools I use in more places, across my projects and my job at Payaza.

Next project: Threadfern