Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

56 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Python FastAPI Docker PostgreSQL

โญ Yelp System โ€” Microservices Architecture

Distributed microservices application for business search and recommendations, powered by the Yelp Open Dataset (~10M+ records).


๐Ÿš€ Overview

This project demonstrates a production-style microservices architecture with:

  • FastAPI-based backend services
  • PostgreSQL database (~10M+ records)
  • gRPC communication between services
  • API Gateway pattern
  • Nginx reverse proxy (rate limiting + security headers)
  • SSR frontend (Next.js)

๐Ÿงญ Quick Architecture Summary

  • API Gateway routes external traffic to internal services
  • Business Service handles search, details, reviews and city data
  • Recommendation Service communicates with Business Service via gRPC
  • PostgreSQL stores the Yelp dataset (~10.2M records)
  • Redis cache-aside layer improves hot read paths
  • Nginx handles reverse proxy, rate limiting and security headers

๐Ÿ–ฅ๏ธ Application Preview

๐Ÿ” Search Page

Search Page

๐Ÿ“„ Business Detail

Business Detail

โญ Recommendations Engine

Recommendations

๐Ÿ“ Reviews System

Reviews


๐Ÿง  System Architecture

Architecture

๐Ÿ“ท Architecture Deep Dive (Latest Diagrams)

System Architecture Overview

System Architecture Overview

Redis Cache-Aside Flow

Redis Cache-Aside Flow

Request Lifecycle (End-to-End)

Request Lifecycle End-to-End

Fail-Open and Resilience

Fail-Open Resilience

Data Ingestion Pipeline

Data Ingestion Pipeline


๐Ÿ—„๏ธ Database Schema

Database

  • ~10.2 million records
  • 5 main tables: businesses, users, reviews, tips, checkins
  • Indexed for performance (city, stars, review_countโ€ฆ)

๐Ÿ” Core Features

  • โœ… Business search (city + rating filters)
  • โœ… Full-text search with runtime path control (search_path=auto|fts|trigram|legacy)
  • โœ… Business detail page (categories, location, status)
  • โœ… Recommendation engine (distance + category + rating)
  • โœ… Reviews system (paginated, sorted)
  • โœ… Interactive map on business detail (Leaflet + OpenStreetMap)
  • โœ… Redis cache layer (cache-aside, stampede protection, rollout flags, observability)
  • โœ… Event-driven cache invalidation (Debezium + Kafka CDC consumer)
  • โœ… gRPC communication between services
  • โœ… API Gateway routing & validation
  • โœ… Rate limiting + security headers (Nginx)
  • โœ… Dockerized infrastructure

๐Ÿงฎ Recommendation Logic

Recommendations are calculated based on:

  • ๐Ÿ“ Geographic proximity (Haversine distance)
  • ๐Ÿท๏ธ Category overlap
  • โญ Rating similarity
  • ๐Ÿ”ฅ Popularity (review count)
  • ๐ŸŸข Business status (open/closed)

Custom scoring function ranks candidates and returns the most relevant results.


๐Ÿ“Š Data

Table Records
businesses 150,346
users 1,987,897
reviews 6,990,280
tips 908,915
checkins 131,930
Total ~10.2M

๐Ÿงช Running the Project

๐Ÿš€ Quick Start

Run the full system locally using Docker:

docker compose up --build

After startup, open:

๐Ÿ‘‰ http://localhost ๐Ÿ‘‰ http://localhost/api/businesses


๐Ÿ” Environment Variables

The project uses a layered environment configuration:

  • .env.example โ€” committed template (safe defaults)
  • .env โ€” local private overrides (not committed)
  • production secrets are injected via CI/CD or runtime environment

For full setup details:

๐Ÿ‘‰ docs/environment-variables.md


โ–ถ๏ธ Local Development

Start each service individually:

# Activate virtual environment
.\venv\Scripts\Activate.ps1

# Business Service
cd services/business-service
uvicorn app.main:app --port 8001 --reload

# Recommendation Service
cd services/recommendation-service
uvicorn app.main:app --port 8002 --reload

# API Gateway
cd services/api-gateway
uvicorn app.main:app --port 8000 --reload

# Frontend
cd services/frontend
npm run dev

Frontend runs at: http://localhost:3000


๐Ÿณ Docker Setup (Recommended)

Run the full system:

docker compose up --build

After startup:

URL Service
http://localhost Nginx โ†’ Frontend
http://localhost/api/businesses API
http://localhost:3000 Frontend (direct)

โš ๏ธ Notes

  • Large dataset (~10M records) is not bundled into Docker images.
  • Import is handled separately to avoid oversized images and slow builds.
  • Rebuild containers after major backend/frontend/config changes:
docker compose build --no-cache
docker compose up -d

๐Ÿงฐ Tech Stack

Layer Technology
Frontend Next.js, React, TypeScript, Leaflet
Backend FastAPI, Python
Cache Redis 7 (cache-aside, LRU)
Database PostgreSQL
ORM SQLAlchemy
RPC gRPC
Proxy Nginx
Containers Docker

๐Ÿ“ˆ Load Testing

The system includes traffic testing for individual services and endpoints.

Tracked metrics:

  • success rate
  • errors
  • average RPS
  • P95 latency
  • service-by-service endpoint behavior

๐Ÿง  Engineering Focus

This project focuses on understanding how backend services communicate, how traffic flows through an API gateway, how data-heavy systems behave under load, and how caching, indexing and service boundaries affect performance.

Consolidated implementation report (professional summary of completed platform upgrades):


โšก Redis Caching

Production-grade cache-aside layer built on Redis 7 for high-traffic read routes:

  • GET /businesses/{id} โ†’ business.details (TTL 60 min)
  • GET /businesses/cities โ†’ business.cities (TTL 12 h)
  • GET /recommendations/{id} โ†’ recommendation.by_business (TTL 15 min)

Implemented capabilities:

  • TTL jitter (ยฑ15%) to prevent synchronized expiry spikes
  • Stampede protection with distributed lock (SET NX PX)
  • Fail-open behavior when Redis is unavailable (services continue via DB/gRPC)
  • Canary rollout controls (CACHE_ROLLOUT_PERCENT, CACHE_SHADOW_MODE)
  • Invalidation after ingestion writes
  • Redis hardening (allkeys-lru, 256 MB cap, requirepass, AOF + RDB, persistent volume)
  • Per-service stats endpoint: /cache/stats

Docs:

CDC smoke test helper:

powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\cdc-smoke-test.ps1 -SkipBringUp

๐Ÿ“ก API Endpoints

All external requests go through the API Gateway (:8000).


๐Ÿ”Ž Search & Observability

Business search supports runtime path control with safe fallback (auto | fts | trigram | legacy) and emits structured metrics through headers and logs.

For full details (query params, fallback behavior, response headers, search_metrics fields, cURL examples, and frontend debug panel), see:


๐Ÿ” JWT Authentication (API Gateway)

The API Gateway validates bearer tokens, required roles, and runtime user status before forwarding protected requests.

For full details (claims, 401/403 behavior, env configuration, cURL examples, and frontend token propagation), see:


๐Ÿข Business Endpoints

Method Endpoint Description
GET /businesses Search businesses (?city=, ?query=, ?search_path=, ?min_stars=, ?page=, ?limit=)
GET /businesses/{id} Get business details by ID
GET /businesses/{id}/reviews Get paginated reviews (?page=, ?limit=)

โญ Recommendation Endpoints

Method Endpoint Description
GET /recommendations/{id} Get similar businesses (?limit=)

โค๏ธ Health Check

Method Endpoint Description
GET /health API Gateway health status

๐Ÿ“Œ Notes

  • Built as a production-style system design project

  • Focus on:

    • scalability
    • service isolation
    • clean architecture
  • Dataset: Yelp Open Dataset (~10M+ records)

Additional implementation and debugging notes are available in docs/engineering-notes.md.

๐Ÿ‘ค Author

Stjepan Velc

Backend Developer focused on Python, FastAPI, PostgreSQL, and distributed systems.

Interested in:

  • system design
  • data-intensive applications
  • scalable backend architecture

๐Ÿ”— GitHub: https://github.com/StjepanVelc

About

Production-style microservices system for business search & recommendations using FastAPI, PostgreSQL, gRPC and Next.js

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages