System Design & Internals

Platform Architecture

Event-driven, serverless cloud topology engineered for zero idle compute costs, atomic inventory reservations, and automatic scaling during high-traffic textile sale events.

Part I

Logical Architecture

Single-table entity domain model, order state progression automata, atomic inventory reservation logic, and idempotent payment webhook handling.

1. LOGICAL PERSONAS & INTERFACE DOMAINS Shopper Storefront (React 19) Merchant Operations Desk Paytm & Shiprocket Webhook Handlers 2. BUSINESS LOGIC & STATE AUTOMATA Catalog Engine Products, fabrics, swatches Atomic Reservation TransactWriteItems isolation Order Lifecycle FSM Pending → Confirmed → Shipped Idempotency Guard Deduplicated payment tokens 3. PAYMENT GATEWAY & CARRIER ORCHESTRATION Paytm Payment Gateway Integration HMAC-SHA256 checksum verification & refund dispatch Shiprocket Carrier Logistics Integration Automated AWB assignment & real-time shipping webhooks 4. SINGLE-TABLE DYNAMODB TRANSACTIONAL DATA MODEL PRODUCT# / VARIANT# Zero-join category & price indexing ORDER# / ITEM# Transactional order details & items CUSTOMER# / LEDGER# Immutable payment audit trail

Atomic Inventory Reservations

During high-traffic textile drops, overselling is physically prevented using DynamoDB TransactWriteItems condition expressions. Stock is decremented and order record created in one atomic transaction.

Order Lifecycle State Machine

Strict state automata transitions: PENDING → PAYMENT_PROCESSING → CONFIRMED → SHIPPED → DELIVERED. Cancellations enforce automated refund requests via Paytm before inventory restock.

Idempotent Webhook Processing

Paytm payment callbacks are cryptographically verified using HMAC-SHA256 checksums and checked against an idempotency ledger to prevent duplicate fulfillment or double refunds.

Single-Table Query Optimization

Global Secondary Indexes (GSI1-PK/SK) allow retrieval of customer order histories, product catalog listings, and category trees with zero relational JOIN penalties.

Part II

Technical Architecture & Physical AWS Infrastructure

Event-driven, serverless cloud topology engineered for zero idle compute costs, atomic inventory reservations, and automatic scaling during high-traffic textile sale events.

1. AWS EDGE ROUTING & WAF SECURITY Route 53 DNS & CloudFront Global CDN (TLS 1.3) AWS WAF v2 (Rate Limiting, SQLi / XSS Shield) 2. SERVERLESS API GATEWAY & LAMBDA RUNTIME Amazon API Gateway (HTTP/REST) • Cognito User Pool Authorizer (Admin) • Paytm Webhook Signature Authorizer • Throttle: Burst 50, Rate 100 req/sec AWS Lambda API Runtime (Koa.js) • Architecture: ARM64 (Graviton), Node.js 22 LTS • Memory: 512 MB, Timeout: 29s, Cold Boot < 250ms • Sub-10ms warm execution latency 3. PERSISTENCE & STATIC ASSET STORAGE Amazon DynamoDB Single-table transactional store On-Demand capacity with PITR S3 Static Web Hosting Customer & Admin SPA buckets Private origin access control (OAC) S3 Product Assets Optimized WebP swatches & photos CloudFront edge compression 4. EXTERNAL INTEGRATION GATEWAYS & ALERTS Paytm Payment Gateway API Order tokenization & refund webhook Shiprocket Logistics API AWB booking & shipping manifest Amazon SES & CloudWatch Order emails & automated SLA alarms

Serverless Scalability & Cost

Zero idle compute costs. AWS Lambda (ARM64 Graviton) scales from 0 to thousands of concurrent executions instantaneously during flash sales, billed per millisecond of compute.

Edge Security & Origin Shield

CloudFront CDN with AWS WAF protects against DDoS, brute force, and injection attacks. Origin Access Control (OAC) ensures S3 asset buckets cannot be accessed directly from the public internet.

DynamoDB High Durability

Single-table DynamoDB replicates data across 3 AWS Availability Zones synchronously. Point-in-time recovery (PITR) preserves continuous backups with zero operational maintenance.

Disaster Recovery & Latency

Static web assets served globally via CloudFront with sub-20ms edge latencies. Lambda cold starts minimized to under 250ms via bundled ES modules. RPO = 0, RTO < 60 seconds.

DynamoDB Single-Table Schema

To avoid RDS connection pooling overhead and cold-start connection penalties, all entities reside in a single high-performance DynamoDB table.

Entity Partition Key (PK) Sort Key (SK) GSI1-PK / GSI1-SK Attributes
Product PRODUCT#<productId> METADATA CATEGORY#<slug> / PRICE#<cents> Title, SKU, basePrice, images, stockCount, tags
Product Variant PRODUCT#<productId> VARIANT#<variantId> SKU#<skuCode> / METADATA Color, size, fabric, stockQuantity, priceDelta
Customer Order ORDER#<orderId> DETAILS CUSTOMER#<custId> / CREATED#<isoDate> Items, totalAmount, status, paytmTxnId, shippingAddress
Order Item ORDER#<orderId> ITEM#<sku> — Unit price, quantity, color, product title
Inventory Lock LOCK#<sku> ORDER#<orderId> — Reserved units, lockExpiresAt (TTL attribute)

Order Lifecycle State Machine

Atomic state transitions ensure no double-charging, no phantom inventory reservations, and 100% automated refund processing.

1

Checkout & Lock

Customer initiates payment. Inventory reservation lock is created with a 15-minute TTL. Transaction token generated via Paytm API.

2

Payment Verification

Asynchronous webhook from Paytm received. HMAC checksum validated. If verified, order status updates to CONFIRMED and stock is permanently decremented.

3

Dispatch & Delivery

Shiprocket AWB generated automatically. Label printed in merchant desk. Customer receives tracking SMS & email.

4

Cancellation & Refund

If cancelled by merchant or customer, Lambda calls Paytm Refund API. On success, stock units are atomically incremented back to inventory.