Infrastructure Overview
This article provides a comprehensive overview of the infrastructure that powers the Thinvent public website. We'll cover the complete technology stack, from the web server to the database layer, and explain how all components work together to deliver a fast, reliable, and scalable e-commerce experience.
Web Application Stack
Flask - The Foundation
Our website is built on Flask, a lightweight and flexible Python web framework. Flask provides the core routing, request/response handling, and blueprint system that organizes our application into modular components.
Key Flask features we use:
-
Blueprints: Organize the application into logical modules (web, api, cart, product, etc.)
-
Jinja2 templating: Server-side HTML generation with template inheritance
-
Request context: Automatic handling of HTTP requests and sessions
-
Werkzeug: Development server and utility functions
The Flask application is initialized in the web module where we:
-
Create the web blueprint
-
Initialize Babel for internationalization
-
Configure Valkey session storage
-
Set up context processors for template variables
Gunicorn - Production Server
For production, we use Gunicorn (Green Unicorn), a Python WSGI HTTP server. Gunicorn runs our Flask application with multiple worker processes.
Gunicorn is managed by systemd, which ensures it automatically restarts if it crashes or the server reboots. This gives us high availability without manual intervention.
Nginx - Reverse Proxy & Load Balancer
Nginx serves as our reverse proxy and load balancer. It sits in front of Gunicorn and handles:
-
SSL/TLS termination: HTTPS encryption/decryption
-
Static file serving: CSS, JavaScript, images (served directly from disk)
-
Reverse proxy: Forward dynamic requests to Gunicorn
-
Rate limiting: Protect against abuse
-
Request compression: Gzip compression for faster transfers
Ubuntu - Operating System
All EC2 instances run Ubuntu, our chosen Linux distribution. We prefer using Ubuntu python packages when available, over pip.
The typical request flow is:
flowchart LR
A[Client Browser] -->|HTTPS Request| B[Nginx]
B -->|Proxy to| C[Gunicorn]
C -->|WSGI| D[Flask App]
D -->|Query| E[Valkey Cache]
E -->|Miss| F[DynamoDB]
F -->|Response| E
E -->|Hit| G[Response]
G --> B
B -->|Response| ACloudFront - Content Delivery Network
CloudFront is our CDN, providing:
-
DDoS protection: Built-in protection against distributed attacks
-
Origin shielding: Protects our origin servers from traffic spikes
Our CloudFront distribution has two origins:
-
Backend server: Backend Flask app
-
S3: S3 bucket for static assets
Cache behaviors configured:
-
/s/*- Static assets (CSS, JS, images) with 24-hour TTL -
/ds/*.pdf- Datasheets with 24-hour TTL -
/api/*- API endpoints with no caching -
/cart- Cart with 24-hour TTL -
/set-language- No caching (dynamic)
Data Layer
DynamoDB - Primary Database
We use Amazon DynamoDB as our primary database. DynamoDB is a NoSQL database.
Our DynamoDB tables include:
-
Recommendations: AI-generated product recommendations
-
Product descriptions: Product descriptions in multiple languages
-
Query pages: Parsed query pages for SEO
We use PynamoDB, a Pythonic ORM for DynamoDB, which provides:
- Model definitions: Python classes for database tables
Valkey - In-Memory Cache
Valkey (a fork of Redis) is our in-memory cache layer, providing:
-
Session storage: User sessions with 30-day sliding expiry
-
Frequently accessed data: Product counts, popular queries
-
Autocomplete cache: Search suggestions
-
Image manifest: Product image locations
Valkey provides significant performance benefits:
-
100x faster than DynamoDB for read operations
-
Reduced database load: Cache hits avoid DynamoDB queries
-
Session persistence: Valkey-backed sessions across requests
We use Valkey for:
-
Sessions: User login state, cart data
-
Caching: Popular queries, autocomplete suggestions
-
Counters: Product stock counts (cached for performance)
-
Queues: Background job processing
S3 - Object Storage
Amazon S3 is our object storage service.
We use S3 for:
-
Product images: High-resolution product photos
-
Datasheets: PDF product specifications
-
Static assets: CSS, JS, images
DNS & Routing
Route53 - Domain Management
Route53 handles our DNS management:
- Domain registration: thinvent.in and related domains
Nginx Routing
Nginx routes requests based on URL patterns:
-
/→ Flask app (home, products, cart, checkout) -
/q/→ Flask app (query pages, search results) -
/api/→ Flask app (API endpoints) -
/static/→ CloudFront/S3 (static assets)
Search & AI Infrastructure
Search Service
We run a standalone Flask application for search functionality. This service provides:
-
Vector search: Semantic similarity for related queries
-
Autocomplete: Prefix-based search suggestions
-
Popular queries: Most searched terms
-
Filter extraction: Parse search queries for facets
The search service uses:
-
Valkey RediSearch: Vector similarity search
-
SentenceTransformer: Embedding generation
-
Phrase mappings: Filter extraction via substring matching
AI Providers
We use multiple AI providers for different tasks:
DeepSeek
-
Model: deepseek-chat
-
Use cases: Product descriptions, query page content, translation
-
API: DeepSeek API with Together.ai fallback
-
Caching: System prompts for prompt caching efficiency
Gemini
-
Model: Gemini (specific model)
-
Use cases: Content generation
-
Integration: Direct API calls
Amazon Bedrock
-
Models: Nova Pro
-
Use cases: Internal chat
-
Integration: boto3 SDK
Amazon Bedrock
-
Models: Nova Lite
-
Use cases: Customer chatbot
-
Integration: boto3 SDK
Complete Request Flow
Here's how a typical request flows through our infrastructure:
flowchart TD
A[Client Browser] -->|DNS Query| B[Route53]
B -->|IP Address| C[CloudFront]
C -->|Cache Check| D{Cache Hit?}
D -->|Yes| E[Return Cached Content]
D -->|No| F[Nginx]
F -->|Proxy| G[Gunicorn]
G -->|WSGI| H[Flask App]
H -->|Cache Check| I[Valkey]
I -->|Hit| J[Return Cached Data]
I -->|Miss| K[DynamoDB]
K -->|Query| L[Return Data]
L --> I
J --> M[Build Response]
E --> M
M --> N[Send to Client]Monitoring & Health
UptimeRobot - External Monitoring
We use UptimeRobot for external monitoring of all public-facing endpoints:
-
Backend server: Backend website
-
www.thinvent.in: Public website
Health Checks
-
Gunicorn: systemd manages restarts
-
Flask:
/healthendpoint returns status -
Valkey: Connection health monitored
-
DynamoDB: Latency and throughput monitored
Logging
-
Application logs: Gunicorn error.log
-
Access logs: Gunicorn access.log
-
Email: Real-time notifications for critical events with Python tracebacks
Summary
Our infrastructure is designed for:
-
Performance: Multiple caching layers, CDN, optimized queries
-
Scalability: Auto-scaling databases, load balancing
-
Cost-effectiveness: Pay-per-use, caching to reduce database load
The combination of Flask, Gunicorn, Nginx, Ubuntu, DynamoDB, Valkey, CloudFront, and UptimeRobot provides a robust, scalable foundation for our e-commerce platform.
Related Articles
-
Analytics Architecture - Learn about our hybrid analytics approach
-
SEO Pipeline - Understand how search queries become product pages
-
Search Service Architecture - Dive into our search infrastructure
-
Caching Strategy - Explore caching at all layers
-
Deployment Architecture - See how the system is deployed
-
Security Considerations - Review security measures