Selected work
Clean Architecture & SecurityLive

ContactHub Backend Service

Full-stack contact management engine live at contact-manager-fawn-alpha.vercel.app — Go clean architecture, bcrypt crypto, and partial unique indexing.

Uniform 404
Tenant Isolation

Missing, deleted and unauthorised records answer identically, so contact IDs cannot be enumerated

30-day window
Soft Delete

Background worker purges 1,000 rows per batch, with graceful shutdown

token_version
Session Revocation

A password reset invalidates every outstanding JWT without a denylist

pg_trgm GIN
Search

Case-insensitive substring search, LIKE metacharacters escaped

(01)· The problem

A contact API that holds several users' data has to be wrong only once to leak it. Scoping queries by user is the easy half; the hard half is that a 404 for a record that does not exist, one that was deleted, and one that belongs to somebody else all have to be indistinguishable, or the IDs can be walked. Authentication adds its own: a login that answers faster for unknown emails than for real ones tells an attacker which addresses are registered.

(02)· How it works
Four layers, one directionUnidirectional dependency
  1. 01
    Chi router v5Transport

    JSON decoding, route validation and a single error envelope shape.

    Validation at the edge
  2. 02
    Service layerBusiness

    bcrypt verification, JWT issue carrying token_version, domain rules.

    Timing-safe on unknown emails
  3. 03
    Repository (SQL)Persistence

    Parameterised queries, every one scoped WHERE user_id = $1.

    Tenant isolation
  4. 04
    PostgreSQLDatabase

    Partial unique index on (user_id, phone) WHERE deleted_at IS NULL.

    Soft delete stays restorable
  • Timing-Safe Account Enumeration Defence

    An unknown email still pays the cost of a bcrypt comparison against a dummy hash, so response time cannot be used to discover which accounts exist.

  • Partial Unique Index on Soft Delete

    Phone uniqueness is scoped per user and to live rows only, so a deleted contact can be recreated or restored without colliding with its own tombstone.

  • Instant Session Revocation Without Redis

    A token_version column in PostgreSQL is carried in the JWT claims; a password reset increments it and every previously issued token stops validating.

(03)· Decisions worth defending
01

A dummy bcrypt verification for emails that do not exist

An unknown email normally returns 401 in about 2ms while a real one pays roughly 70ms for the hash comparison, and that gap is a free list of who has an account. Running a bcrypt comparison against a pre-computed hash for unknown users makes the two paths take the same time.

02

A partial unique index scoped to live rows, not a table-wide constraint

A global UNIQUE on phone would stop two different users saving the same number, and stop anyone restoring a contact they had deleted. A composite partial index on (user_id, phone) WHERE deleted_at IS NULL scopes uniqueness to one user and to records that are actually active.

03

A token_version column instead of a session store

Revoking a session instantly usually means keeping state somewhere — a Redis denylist, and a new dependency to run and fail. Carrying a version number in the JWT claim and bumping the column on password change invalidates every outstanding token at once, with the database already there.

(04)· What is still wrong with it

The rate limiter only works because there is one container. internal/ratelimit holds its per-IP and per-account counters in process, so they reset on every restart and do not hold across replicas — put two instances behind a load balancer and each one happily enforces its own separate budget, which is to say neither enforces the limit. It is the right amount of machinery for a single box and the wrong amount the moment there are two. The shortener solves the same problem with an atomic Redis Lua script over a sorted set; that is where this one should go.

(05)· Built with
GoPostgreSQLDockerJWTREST APIClean Architecturebcrypt
NextURL Shortener
Elvin Rodrigues
Elvin Rodrigues*

Backend engineer. Go, PostgreSQL, Redis, and the parts of a system that only show up under load.

Local time
—:—:— IST
Nitte, Karnataka, India
© 2026 Elvin Rodrigues · All rights reservedBack to top