System Architecture
The e-commerce API is built on a modern, scalable architecture designed to handle high-traffic retail operations. The system uses a microservices-oriented approach with multiple data stores and caching layers.Technology Stack
Core Framework
Falcon WSGI Framework- Lightweight, high-performance Python web framework
- RESTful API design with explicit routing
- Minimal overhead for maximum throughput
- Custom middleware pipeline for request processing
Database Layer
The platform uses a multi-database architecture for optimal performance and scalability:MySQL
Primary relational database for transactional data
- Write Instance: Product catalog, orders, users
- Read Replica: Query optimization and load distribution
- Connection pooling with SQLAlchemy ORM
MongoDB (DocumentDB)
NoSQL database for flexible schema data
- Product metadata and catalogs
- Shopping cart persistence
- Session and analytics data
Redis
In-memory data store for caching
- Multiple Redis instances for different purposes
- Session management and user tokens
- Real-time inventory buffers
Elasticsearch
Search and analytics engine
- Product search and filtering
- User behavior analytics
- Recommendation engine data
Database Configuration
The API uses separate read and write connections to MySQL, allowing for horizontal scaling and improved query performance.
Middleware Pipeline
Requests flow through a series of middleware components that handle cross-cutting concerns:Middleware Components
DatabaseManager
DatabaseManager
Manages database connections throughout the request lifecycle.Responsibilities:
- Injects MySQL and MongoDB sessions into request context
- Handles automatic commit/rollback on response
- Manages connection pooling and cleanup
- Separates read/write database operations
AuthHandler
AuthHandler
Handles JWT token validation and user authentication.Features:
- JWT token decoding (standard and 512-bit)
- User data caching in Redis (5-10 min TTL)
- Two-factor authentication support
- Public endpoint optimization (skips DB lookup)
- Token blacklist validation
CartMiddleware
CartMiddleware
Manages shopping cart state and persistence.Features:
- Loads cart only for whitelisted endpoints (performance optimization)
- Merges browser cart with server-side cart
- Supports hyperlocal and split order modes
- MySQL-based cart persistence
- Lazy calculation of cart totals
/api/v2/cart,/api/v2/validatecheckout/api/v2/processorder,/api/v2/order- Coupon and gift voucher endpoints
BlacklistHandler
BlacklistHandler
Prevents access from blacklisted IPs and user agents.
- Dedicated Redis instance for blacklist data
- Real-time blocking without database queries
JSONTranslator
JSONTranslator
Automatically parses request body JSON and injects into
req.context['data'].Caching Strategy
The platform implements a multi-tier caching strategy using Beaker and Redis:Cache Regions
Redis Instances
Multiple Redis instances serve different purposes:| Instance | Purpose | Configuration |
|---|---|---|
| Primary Redis | General caching, Beaker backend | REDIS_HOST:REDIS_PORT |
| User Redis | User session data, auth cache | USER_REDIS_HOST:USER_REDIS_PORT |
| Payment Redis | Payment processing state | PAYMENT_REDIS_HOST:PAYMENT_REDIS_PORT |
| Buffer Redis | Inventory buffer, real-time stock | REDIS_BUFFER_HOST:REDIS_BUFFER_PORT |
| Blacklist Redis | IP/user-agent blacklisting | BLACKLIST_REDIS_HOST:BLACKLIST_REDIS_PORT |
| CMS Redis | Content management cache | CMS_REDIS_HOST:CMS_REDIS_PORT |
The use of dedicated Redis instances prevents cache invalidation conflicts and allows for independent scaling based on workload.
API Versioning
The API supports multiple versions through URL prefixes:Background Processing
Asynchronous tasks are handled by Celery with multiple queues:CELERY_KINESIS_ORDER_QUEUE- Order stream processingCELERY_KINESIS_PRODUCT_QUEUE- Product sync to KinesisCELERY_CANCEL_ORDER_QUEUE- Order cancellation workflowsCELERY_ORDER_REFUND_QUEUE- Refund processingCELERY_COMMS_QUEUE- Communication events (email, SMS)SYNC_QUEUE- Data synchronization tasks
Infrastructure Components
AWS Kinesis
Real-time data streaming for:
- Order events
- Product updates
- Analytics pipelines
AWS SQS
Message queuing for:
- Webhook logging
- User blocking events
- Warehouse assignments
AWS S3
Object storage for:
- Product images
- Generated sitemaps
- Export files
Gunicorn + WSGI
Production server:
- Multi-worker processes
- Custom gunicorn configuration
- Health check endpoints
CORS Configuration
The API supports CORS for authorized domains:Performance Optimizations
Connection Pooling
All database connections use pooling to reduce overhead:Public Endpoint Optimization
Public catalog endpoints skip user authentication database queries when no auth token is provided, significantly reducing database load:Cart Middleware Whitelisting
Cart data is only loaded for endpoints that actually need it, avoiding unnecessary database queries:These optimizations reduce database queries by up to 70% for anonymous browsing traffic.
Deployment Architecture
The application is containerized using Docker:Dockerfile- Main application containerDockerfile-celery- Celery worker containerDockerfile-flower- Celery monitoringdocker-compose.yml- Multi-service orchestration
Monitoring & Observability
The platform integrates with multiple monitoring services:- New Relic - Application performance monitoring
- Elasticsearch - Log aggregation and search
- Slack - Exception notifications and alerts
- Health check endpoint:
/api/v2/health