Portfolio & Live Telemetry Platform
This website: a TypeScript backend with Redis caching, async event ingestion, rate limiting and live observability.
- TypeScript
- Node.js
- Fastify
- PostgreSQL
- Redis
- Next.js
A Fastify API in a layered MVC structure backed by PostgreSQL and Redis. Content is served cache-aside with single-flight loading and TTL jitter; telemetry events are buffered in Redis and flushed in batches by a worker; the contact form is protected by an atomic Lua sliding-window rate limiter. Every retry and fallback is logged and counted in Prometheus metrics.
How a page is served
Each page is rendered on the server by Next.js from the API's data, so content changes appear without rebuilding the site.
- The API reads content through a Redis cache (cache-aside): a hit is answered from memory; a miss loads the data from PostgreSQL and keeps a copy for about five minutes.
- Expiry times are spread out at random so entries don't all expire at once, and simultaneous misses for the same data share a single database query.
- If Redis fails, content is served straight from PostgreSQL, and the fallback is logged and counted.
- Content is written in a JSON file, checked in full, and saved to the database in one transaction, so a mistake never publishes half an update.
Visitor analytics
Page views are recorded without slowing the page down: the API accepts each event almost instantly and a background worker does the rest.
- The browser sends a small event; the API validates it and adds the visitor's country, organisation and browser from local lookups. The raw IP address is never stored.
- Unique visitors are counted with a hash that changes every day, so no one can be followed from one day to the next.
- Events wait in a Redis queue, and a worker writes them to PostgreSQL in batches.
- Failed writes are retried with increasing delays; an event that can never be stored is set aside in a dead-letter queue and can be replayed later.
Contact form and rate limiting
Messages are saved first and delivered in the background, so a slow or failing notification service never loses one.
- A sliding-window rate limiter, written as a Lua script that runs atomically inside Redis, allows three messages per sender every ten minutes, even when requests reach different servers at the same moment.
- Each message is stored in PostgreSQL, and a job is queued for a worker that forwards it to Discord.
- Failed deliveries are retried with exponential backoff, then moved to a dead-letter queue; a reconciler re-queues any message whose job never made it into the queue.
Monitoring
- Prometheus metrics cover request latency, cache hit ratio, queue sizes, retries and fallbacks.
- The public status page shows live health, response times (p50 and p95), the cache hit ratio and queue sizes, refreshed every five seconds.
- Structured logs carry a request ID, so one request can be followed through every layer.
Engineering practices
- A layered API: controllers handle HTTP, managers hold the business rules, and data-access modules are the only code that talks to PostgreSQL or Redis.
- Strict TypeScript; every input from outside is validated, and the API and the website share one set of request and response schemas.
- Over 300 automated tests, including integration tests against real PostgreSQL and Redis, run on every pull request in GitHub Actions.
- Graceful shutdown: on a restart, requests in progress finish and the worker drains its queue before stopping.