Version: 1.0.0
Last Updated: 2026-02-17
Status: Production-Ready
This document describes the architecture, design decisions, and data flow for the Price Aggregator Microservices system. The system follows a microservices architecture pattern with clear service boundaries, internal communication, and a layered security model.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ External Layer โ
โ โโโโโโโโโโโโโโ โ
โ โ Internet โ โ
โ โโโโโโโฌโโโโโโโ โ
โ โ โ
โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโผโโโโโโ
โ User โ
โโโโโโฌโโโโโโ
โ
โ HTTP
โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Presentation Layer โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Frontend (React + Nginx) โ โ
โ โ Port: 3000 (Exposed) โ โ
โ โ - User Interface โ โ
โ โ - Product Search โ โ
โ โ - Results Display โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ HTTP REST
โโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Layer โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Node.js API Gateway (Express) โ โ
โ โ Port: 5000 (Exposed) โ โ
โ โ - Authentication (JWT) โ โ
โ โ - Rate Limiting โ โ
โ โ - Request Routing โ โ
โ โ - Input Validation โ โ
โ โ - Service Orchestration โ โ
โ โโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ โ
โ โ โ โ
โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โ Internal HTTP โ MongoDB Protocol
โ โ
โโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Service Layer โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Python Collector (FastAPI)โ โ MongoDB โ โ
โ โ Port: 8000 (Internal) โ โ Port: 27017 โ โ
โ โ - Web Scraping โ โ (Internal) โ โ
โ โ - Data Collection โ โ - User Data โ โ
โ โ - Price Aggregation โ โ - Product Cache โ โ
โ โ - Data Normalization โ โ - Auth Storage โ โ
โ โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โ Redis Protocol โ
โ โ โ
โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ โ
โ โ Redis Cache โ โ
โ โ Port: 6379 (Internal)โ โ
โ โ - Session Storage โ โ
โ โ - Query Cache โ โ
โ โ - Rate Limit Store โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โUserโโโโโโถโ Frontend โโโโโโถโ Gateway โโโโโโถโ Python โ
โโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ Collector โ
โโโโโโโโฌโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโ
โ Redis โ
โ Cache โ
โโโโโโโโโโโโโโโโ
1. User enters search query in Frontend
2. Frontend sends HTTP GET to Gateway (/search?query=laptop)
3. Gateway validates request and checks authentication
4. Gateway forwards request to Python Collector (internal)
5. Python Collector checks Redis cache for existing results
6. If cache miss, scrapes product data from sources
7. Python Collector normalizes and returns data
8. Gateway adds metadata and returns to Frontend
9. Frontend displays results to user
โโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โUserโโโโโโถโ Frontend โโโโโโถโ Gateway โโโโโโถ โ MongoDB โ
โโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโ
โ Redis โ
โ Session โ
โโโโโโโโโโโ
Login Flow:
1. User submits credentials via Frontend
2. Frontend POSTs to /auth/login
3. Gateway validates credentials against MongoDB
4. Gateway generates JWT token
5. Gateway stores session in Redis
6. Gateway returns token to Frontend
7. Frontend stores token for subsequent requests
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโ
โ Gateway โโโโโโถโ Python โโโโโโถ โ External โ
โ โ โ Collector โ โ E-commerceโ
โโโโโโโโโโโโโโโโ โโโโโโโโฌโโโโโโโ โ Sites โ
โ โโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโ
โ Redis โ
โ Cache โ
โโโโโโโโโโโโโโโโ
1. Gateway calls Python Collector endpoint
2. Collector initiates parallel scraping tasks
3. Collector fetches data from multiple sources
4. Data is normalized and deduplicated
5. Results cached in Redis with TTL
6. Aggregated data returned to Gateway
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Docker Bridge Network (internal-network) โ
โ Subnet: 172.28.0.0/16 โ
โ โ
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ
โ โ Frontend โ โ Gateway โ โ Python โ โ
โ โ โ โ โ โCollector โ โ
โ โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ โ
โ โ โ โ โ
โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโผโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโผโโโโโ โโโโโโผโโโโโ โ
โ โ MongoDB โ โ Redis โ โ
โ โโโโโโโโโโโ โโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
Port 3000 Port 5000
โ โ
Exposed to Host Network
| Service | Internal Port | Exposed Port | Access Level |
|---|---|---|---|
| Frontend | 3000 | 3000 | Public |
| Node Gateway | 5000 | 5000 | Public |
| Python Collector | 8000 | - | Internal Only |
| MongoDB | 27017 | - | Internal Only |
| Redis | 6379 | - | Internal Only |
Security Rationale:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Layer 1: Network Isolation โ
โ - Internal Docker network โ
โ - No external exposure for backend services โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Layer 2: Container Security โ
โ - Non-root users in all containers โ
โ - Minimal base images (Alpine, Slim) โ
โ - Read-only file systems where possible โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Layer 3: Application Security โ
โ - JWT authentication โ
โ - BCrypt password hashing โ
โ - Rate limiting โ
โ - Input validation โ
โ - Helmet.js security headers โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Layer 4: Data Security โ
โ - Environment-based secrets โ
โ - Encrypted connections โ
โ - Database authentication โ
โ - Password-protected Redis โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Request Flow with JWT:
1. Client Request
โโโถ Authorization: Bearer <JWT_TOKEN>
โ
2. Gateway Middleware
โโโถ Extract token from header
โโโถ Verify signature with JWT_SECRET
โโโถ Check expiration
โโโถ Decode payload
โ
3. Decision
โโโถ Valid: Attach user context to request โ Continue
โโโถ Invalid: Return 401 Unauthorized โ Reject
All internal communication uses container name DNS resolution:
// Gateway โ Python Collector
const PYTHON_URL = process.env.PYTHON_SERVICE_URL;
// "http://python-collector:8000"
// Gateway โ MongoDB
const MONGO_URI = process.env.MONGO_URI;
// "mongodb://admin:pass@mongodb:27017/db"
// Gateway โ Redis
const REDIS_URL = process.env.REDIS_URL;
// "redis://:password@redis:6379/0"
Benefits:
Frontend โโโโโโHTTPโโโโโถ Gateway โโโโโโHTTPโโโโโถ Python
โ
โโโโโโMongoDBโโโโโถ Database
โ
โโโโโโRedisโโโโโโถ Cache
Protocol: HTTP/HTTPS REST
Format: JSON
Pattern: Request-Response
Example:
GET /search?query=laptop HTTP/1.1
Host: node-gateway:5000
Authorization: Bearer eyJhbG...
For scalability, consider adding:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ MongoDB (Primary Database) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Collections: โ
โ - users: User accounts and profiles โ
โ - products: Cached product data (optional) โ
โ - searches: Search history (analytics) โ
โ - sessions: Active user sessions โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Redis (Cache Layer) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Key Patterns: โ
โ - search:<query_hash>: Cached search results โ
โ - session:<user_id>: User session data โ
โ - rate_limit:<ip>: API rate limiting โ
โ - product:<id>: Individual product cache โ
โ โ
โ TTL Strategy: โ
โ - Search results: 1 hour โ
โ - Sessions: 24 hours โ
โ - Rate limits: 15 minutes โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Docker Volumes:
mongodb_data/
โโโ Persistent MongoDB data files
mongodb_config/
โโโ MongoDB configuration
redis_data/
โโโ Redis RDB/AOF persistence
Backup Strategy:
Docker Compose Dependency Graph: frontend
โ
โ depends_on
โผ
node-gateway
โ
โโโโโโโโโโโผโโโโโโโโโโ
โ โ โ
depends_on depends_on depends_on
โ โ โ
โผ โผ โผ
python- mongodb redis
collector
โ
depends_on
โ
โผ
redis
All services implement health checks:
healthcheck:
test: [health check command]
interval: 30s # Check every 30 seconds
timeout: 3s # Fail if no response in 3s
retries: 3 # Try 3 times before marking unhealthy
start_period: 10s # Grace period after container start
Benefits:
Each service can be scaled independently:
# Scale Python collectors for heavy scraping
docker compose up -d --scale python-collector=3
# Scale gateway for high traffic
docker compose up -d --scale node-gateway=2
โโโโโโโโโโโโโโโโ
โ Load Balancerโ
โ (Nginx) โ
โโโโโโโโฌโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ
โ โ โ
โโโโโโผโโโโโ โโโโโโผโโโโโ โโโโโโผโโโโโ
โGateway 1โ โGateway 2โ โGateway 3โ
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
MongoDB Replica Set (Future):
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ Primary โโโโโโโโถโSecondaryโโโโโโโโถโSecondaryโ
โโโโโโโโโโโ โโโโโโโโโโโ โโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโ
โ
Clients
| Benefit | Implementation |
|---|---|
| Independent Deployment | Each service has its own container |
| Technology Diversity | Node.js for API, Python for scraping |
| Fault Isolation | One service failure doesnโt cascade |
| Team Autonomy | Teams can own individual services |
| Scalability | Scale services independently |
| Component | Reason |
|---|---|
| React | Modern UI, component reusability, large ecosystem |
| Express | Mature, middleware-friendly, Node.js ecosystem |
| FastAPI | High performance, async support, auto-generated docs |
| MongoDB | Flexible schema, JSON-native, good for product data |
| Redis | Fast in-memory cache, pub/sub support, simple APIs |
For questions about architecture decisions:
architecture labelDocument Maintained By: DevOps Team
Review Cycle: Quarterly
Last Architecture Review: 2026-02-17