Engineering a Distributed ServerlessE-Commerce Platformfor Modern Agriculture.
An end-to-end e-commerce platform featuring secure Cognito role-based access, fault-tolerant payment flows powered by the Saga pattern, and event-driven architecture for automated notifications.
Orchestrating aServerless Ecosystem.
A unified view of how our Next.js frontends, FastAPI microservices, and AWS infrastructure work together to power a multi-role digital storefront.
The User Portal
High-Performance UX: A Next.js frontend designed for speed, featuring an Amplify-cached catalog, intelligent search, and a seamless Razorpay checkout flow.
The Admin Control Center
Master Data Management: A secure, master-access portal allowing the business owner to push instant seasonal homepage updates, manage product lifecycles, and oversee global order fulfillment.
The Delivery Agent Module
Role-Based Logistics: A specialized UI module restricted via Cognito RBAC. It equips delivery personnel with real-time order routing using embedded Google Maps and reverse geocoding (longitude/latitude) for precise drop-offs.
The Cloud Backbone
Distributed & Event-Driven: A highly scalable Python/FastAPI backend executing entirely on AWS Lambda. State is managed via RDS MySQL, with complex asynchronous tasks orchestrated through AWS Step Functions.
Securing the Perimeter:Multi-Portal Identity & RBAC
Security cannot be a single point of failure. We implemented a federated, Zero-Trust architecture using AWS Cognito to govern identities and access across two entirely distinct web portals.
Dual-Flow Authentication & UI Rendering
To minimize checkout friction, the public User Portal leverages Google SSO via Cognito. Conversely, the internal operations portal enforces strict credential-based logins.
Edge Authentication (The API Layer)
Every REST endpoint is shielded by API Gateway Cognito Authentication. Python Lambdas strictly enforce Role-Based Access Control (RBAC).
Stateful Connection Security
Securing asynchronous communication requires more than standard token checks. We engineered a Custom Lambda Authorizer specifically for WebSockets.
Customer App
Next.jsAdmin App
Next.jsAWS Cognito
Token MachineREST API
WebSocket API
FastAPI / Lambdas
Video Coming Soon
Real interview footage explaining the Cognito architecture is being processed.
The 4-LayerPerformance Shield:Zero-Latency UX.
To make the web platform feel as instantaneous as a native mobile app—while simultaneously protecting our FastAPI backend from redundant database queries—we engineered a sophisticated, 4-tier caching architecture.
Demo Video Coming Soon
Edge Caching (Next.js ISR)
The First Line of Defense: We utilize Next.js Incremental Static Regeneration (revalidate) to cache dynamic product catalogs at the AWS Amplify edge. If 1,000 users search for the same fertilizer, the database is queried exactly once.
In-Memory Mutability (React Query)
Eliminating Network Latency: We integrated React Query (TanStack) to manage data directly in the browser's active memory. Navigating between product details and previously viewed lists results in instant, zero-network-request loads.
Persistent Browser Storage
Bypassing the Server: Heavy, static layout data—such as category trees and global navigation menus—are written directly to LocalStorage. A custom invalidation script ensures the UI instantly loads from the hard drive.
Synchronized Application State
Volatile Session Memory: To prevent component re-renders, highly dynamic data like the shopping cart is held in a centralized React Context. Clicking 'Add to Cart' instantly synchronizes the UI globally without a page refresh.
The Engine Room:
Distributed Transactions & The Saga Pattern
Processing payments requires absolute fault tolerance. We architected a zero-trust, event-driven checkout pipeline utilizing AWS Step Functions to guarantee exact-once execution and seamless rollbacks across our microservices.
Checkout
sapanafertilizer.com
Antracol — Bayer
Fungicide · 1 KG
Order Confirmed
Order #SF-48291
₹661.59 Paid
FastAPI
Idempotency Engine
Checkout — sapanafertilizer.com
Outgoing Payload
shipping_to: "Chandrala"
payment_method: "UPI"
cart_total: "₹1.00"
RDS MySQL
VERIFIED TOTAL
₹14,266
Order Confirmed
₹14,266 Verified
Hack attempt silently ignored
AWS Step Function
Checkout Saga
Order & Logistics
Cart Hydration
Promotion Engine
Discount Calc
Payment Service
Razorpay Intent
Checkout Initialized
Saga completed in 1.2s
Step Function: CATCH
Compensating Transaction
Eventual Consistency Achieved
All domains compensated
API Gateway
WebSocket
Alert Lambda
Non-VPC
Pre-Lambda
Lock DB
Post-Lambda
Finalize
Network Isolation Maintained
$0 egress · Zero NAT costs
Payload-Hashed Idempotency
Preventing Double-Charges
To protect against impatient clicks and network retries, we enforce state-driven idempotency. The frontend generates a deterministic hash from the exact checkout payload. If a user spam-clicks 'Pay Now', FastAPI detects the duplicate hash, short-circuits the AWS Step Function to prevent redundant billing, and returns the existing Order ID. However, altering the value of an even single checkout field generates a new hash, natively unlocking a fresh Saga orchestration.
Zero-Trust Payload Security
Tamper-Proof Financials
We never trust the client with financial data. To eliminate the risk of client-side price manipulation via Chrome DevTools, our frontend payload strictly transmits shipping coordinates and payment preferences—never cart totals. Instead, the REST API extracts the Cognito Sub from the Authorization header to securely fetch the immutable, true cart state directly from our RDS database.
Domain-Driven Saga Orchestration
Distributed Transaction Safety
Because checkout spans multiple microservices, a standard synchronous API risks catastrophic timeouts. We decoupled the flow into an asynchronous AWS Step Function. The Saga routes the payload through strictly sequenced domains—first hydrating the cart to safely persist the immutable records across the Order related tables. It then passes through an extensible Promotion Engine to calculate cascading discounts, before securely generating a tamper-proof Razorpay intent in the Payment Service.
Distributed Compensating Transactions
Cross-Boundary Rollbacks
A standard ORM session.rollback() cannot undo network requests across isolated microservices. This is exactly why we orchestrated the checkout via AWS Step Functions. If the Payment Service fails after the Order and Promotion domains have already committed their data, the Step Function's Catch block intercepts the failure. It natively triggers a compensating Lambda that reaches back across repository boundaries to gracefully release inventory locks, revert applied discounts, and void the transaction state—guaranteeing strict eventual consistency without manual database surgery.
FinOps-Driven VPC
Isolation Zero-Cost Network Egress
Core microservices run in an air-gapped VPC to protect RDS, but rollback failures require public WebSocket alerts. Instead of provisioning an expensive, always-on NAT Gateway, the Step Function acts as a secure network bridge. It orchestrates a 3-stage rollback: a VPC Lambda locks the database state, a non-VPC Lambda broadcasts the alert, and execution returns to the VPC to finalize the rollback. This guarantees strict network isolation with $0 idle infrastructure costs.
Async WebSocket Callbacks
Real-Time UI Updates
Because the Step Function processes the Saga asynchronously, the frontend cannot wait on an HTTP connection. We engineered a bi-directional WebSocket connection via API Gateway. As the Step Function resolves the Razorpay order ID or finalized offline payment, the backend pushes a real-time success or failure notification directly to the client's connection_id, ensuring a seamless, zero-lag user experience.
The Engine Room:
Distributed Transactions
We architected a zero-trust, event-driven checkout pipeline utilizing AWS Step Functions to guarantee exact-once execution and seamless rollbacks.
Spatial Logistics:Precision Routing with Google Maps
Precision Coordinate Capture
Triple-Fallback Logistics: Agricultural addresses can be highly unpredictable. To guarantee exact last-mile routing, we engineered a three-tier location capture UI. Users can leverage Google Places Auto-Suggest, trigger an instant 'Current Location' GPS ping, or manually drag-and-drop a map pin for pinpoint targeting. The frontend seamlessly normalizes these three distinct inputs into strict Longitude/Latitude coordinates for our backend validation engine.
Event-Driven WhatsApp Pipeline:
Bridging the VPC Boundary
To guarantee zero API latency during checkout, we completely decoupled document generation from the main thread. By leveraging AWS S3 Event Notifications, we engineered a highly scalable pipeline to deliver real-time WhatsApp receipts.
Instant Confirmation & The Success Trigger
State-Aware Messaging: Communication maps strictly to the order's lifecycle. The heavy PDF receipt pipeline remains dormant until the order definitively reaches a SUCCESS payment state.
The VPC Boundary & PDF Generation
Cost-Optimized Isolation: Our Receipt Lambda lives strictly inside a private VPC to query RDS. To avoid a $30/mo NAT Gateway just to reach WhatsApp, it uploads the PDF to S3.
The Air-Gap Bridge & WhatsApp Dispatch
Crossing the Network Divide: The S3 upload triggers our external Receipt Message Lambda. By reading the phone number from the S3 metadata, it bridges the network gap flawlessly.
The V2 Roadmap:
Voice-Activated AI Agronomist
Bridging the digital literacy gap. To keep serverless costs under $30/month while ensuring absolute safety, we are architecting a custom, highly-constrained RAG pipeline built on robust AI engineering patterns rather than bloated frameworks.
WHERE MATCH(symptoms)
AGAINST('yellow spots')
to Flip
Operational Excellence:
From Code to Cloud
The Engine Room: Meet the Team

Abhi Patel
Cloud Consultant

Pathik Patel
Tech Lead

Rajvi Patel
Software engineer
Ready to dive deeper into the architecture?