Portfolio
Backend / Systems

E-commerce Backend Engineering Lab

Backend Engineering Lab — Production-Minded E-commerce System

View on GitHub

Overview

A production-minded NestJS e-commerce backend built as an engineering lab to experiment with real backend architecture, test performance characteristics, and study how production systems behave under load. Focuses on caching strategies, observability, data structures, and scalability tradeoffs.

Engineering Goals

  • Experiment with stateless API design patterns
  • Test and compare caching strategies (in-memory LRU vs Redis)
  • Study system behavior under load with k6
  • Apply data structures and algorithms in real services
  • Implement observability with Prometheus metrics and structured logging
  • Observe scalability and performance tradeoffs in practice

System Architecture

  • Stateless API servers with NestJS modular architecture
  • PostgreSQL database with Prisma ORM for type-safe data access
  • Redis for distributed caching and session storage
  • In-memory LRU cache for comparison experiments
  • Prometheus for metrics collection and monitoring
  • Docker containerization for consistent local development
  • Background workers architecture (scaffold for future expansion)

Key Experiments & Learnings

LRU cache implementation: Custom in-memory cache with configurable TTL and size limits

Cache performance comparison: Baseline (no cache) vs in-memory LRU vs Redis

Load testing: k6 scripts for measuring request throughput and latency

Observability patterns: Prometheus metrics, structured logging, request tracing

Database query optimization: Prisma query patterns and indexing strategies

Modular architecture: Clean separation between products, auth, and algorithm modules

Performance & Observability

  • Request duration tracking via Prometheus histograms
  • Cache hit/miss ratio monitoring
  • Memory usage tracking (process_resident_memory_bytes)
  • CPU usage monitoring (process_cpu_seconds_total)
  • HTTP request metrics by route, method, and status code
  • Load testing results comparing baseline vs cached performance

Technical Implementation

  • Modular NestJS architecture with clean separation (products, auth scaffold, algorithms)
  • Custom LRU cache implementation for in-memory caching experiments
  • Redis integration for distributed caching comparison
  • Prometheus metrics endpoint with request tracking and performance monitoring
  • Structured JSON logging with request ID correlation
  • Docker Compose setup for local production-like infrastructure (PostgreSQL, Redis, Prometheus)
  • Load testing scripts with k6 for baseline and cache performance comparison
  • Focus on behavior under load, not feature completeness

Tech Stack

NestJSTypeScriptPostgreSQLPrismaRedisPrometheusDockerk6