- 1. Network Topography & The Edge Delivery Imperative
- Architectural Principles for Indian Edge Deployment:
- 2. Islands Architecture vs. Monolithic Client Hydration
- Astro Islands Component Architecture
- 3. Resilient Payment Gateway Architecture (UPI & NetBanking)
- Production Idempotent Webhook Handler (TypeScript / Node.js)
- 4. Frontend Security: Content Security Policy (CSP) & Subresource Integrity
- Production Strict Nonce-Based CSP Header Template
- 5. Performance Benchmarks: Astro vs. Next.js vs. Vanilla SPA
- 6. Engaging Cyberfact Security for Enterprise Web Engineering
- Our Web Engineering Specializations:
The Indian consumer and enterprise digital ecosystem presents unique engineering challenges. With over 850 million connected internet users operating across heterogeneous network conditionsβranging from gigabit fiber connections in tier-1 metro hubs (Delhi-NCR, Bengaluru, Mumbai) to variable 4G/5G mobile connections across tier-2 and tier-3 towns (Patna, Darbhanga, Jaipur, Indore)βbuilding web applications requires ruthless performance optimization combined with enterprise-grade defensive hardening.
A web application that takes 4.5 seconds to hydrate on a budget smartphone not only suffers severe conversion drop-offs but also risks timeout failures during mission-critical transactions such as Unified Payments Interface (UPI) checkouts.
In this deep architectural paper, Cyberfact Security breaks down the exact full-stack engineering stack, CDN caching paradigms, and payment gateway resiliency patterns required to deliver sub-500ms Largest Contentful Paint (LCP) alongside impenetrable application security.
1. Network Topography & The Edge Delivery Imperative
When serving users across India, physical latency to edge nodes is the dominant variable influencing Time to First Byte (TTFB). Routing all requests through a single cloud region (such as ap-south-1 in Mumbai) adds 40ms to 90ms of round-trip latency for users in northern or eastern regions before application bytecode even begins parsing.
[ User in Tier-2/3 City (Patna / Guwahati) ]
β
βΌ (<15ms Local Edge RTT)
[ Edge Cloudflare / Fastly Anycast Point of Presence (PoP) ]
β β
(Static Cache Hit: 92%) (Dynamic API Miss: 8%)
β β
βΌ βΌ (<30ms Tier-1 Cloud Backbone)
[ Instant Zero-JS Edge Return ] [ Hardened API Gateway (Mumbai Region) ]
Architectural Principles for Indian Edge Deployment:
- Multi-PoP Edge Caching: Utilizing Anycast networks with active points of presence in Mumbai, Delhi, Bengaluru, Chennai, Kolkata, and Hyderabad.
- Tiered Cache Invalidation: Static assets (fonts, WebP images, pre-rendered HTML) cached with immutable cache-control headers (
s-maxage=31536000, immutable), while dynamic content is refreshed via edge webhooks. - Brotli & AVIF Compression: Saving 28% more bandwidth over traditional Gzip, critical for users on variable mobile carrier networks.
2. Islands Architecture vs. Monolithic Client Hydration
Traditional Single-Page Applications (SPAs) built with legacy React or Next.js frameworks bundle 300KB to 800KB of JavaScript into client payloads. On mid-tier mobile processors, JavaScript execution locks the main browser thread for 1.2 to 2.8 seconds, triggering poor Interaction to Next Paint (INP) scores.
Modern architectures adopt the Islands Architecture (pioneered by Astro), rendering 100% pure HTML and CSS by default, and selectively hydrating interactive widgets (Islands) only when scrolled into the viewport.
Astro Islands Component Architecture
---
// Server-Side Rendered (Zero Client JavaScript by default)
import HeroBanner from '../components/HeroBanner.astro';
import EnterpriseFeatures from '../components/EnterpriseFeatures.astro';
// Interactive React Island (Hydrated only when visible)
import InteractivePricingCalculator from '../components/PricingCalculator.tsx';
---
<main>
<!-- Pure static HTML, instant sub-200ms render -->
<HeroBanner />
<EnterpriseFeatures />
<!-- Hydrates React component ONLY when user scrolls to it -->
<InteractivePricingCalculator client:visible />
</main>
By decoupling static content presentation from interactive state, total JavaScript execution time drops by over 85%, guaranteeing 99+ Google Lighthouse scores across mobile profiles.
3. Resilient Payment Gateway Architecture (UPI & NetBanking)
Payment failures in India frequently occur due to bank switch timeouts, flaky mobile network handoffs, or duplicate submissions by impatient consumers. A resilient payment processing architecture must enforce idempotency keys, exponential backoff webhook retry workers, and automated transaction reconciliation.
[ Client Initiates Order ] ββ(Generates UUID v4 Idempotency-Key)ββ> [ API Gateway ]
β
βΌ
[ Razorpay / Cashfree / PayU Intent ] <ββ(Atomic DB Lock on Order ID)ββββββββ€
β β
βΌ (Client Redirect to UPI App: PhonePe / Google Pay / CRED) β
[ User Completes UPI PIN Authorization ] β
β β
βΌ (Webhook Event: payment.captured) βΌ
[ Webhook Ingestion Worker ] ββ(Verify HMAC-SHA256 Signature)ββ> [ SQS / Redis Queue ]
β
βΌ
[ Balance Credit & Order Unlock ]
Production Idempotent Webhook Handler (TypeScript / Node.js)
import { Request, Response } from 'express';
import crypto from 'crypto';
import prisma from '../lib/prisma';
import redis from '../lib/redis';
export async function handlePaymentWebhook(req: Request, res: Response) {
const webhookSignature = req.headers['x-razorpay-signature'] as string;
const webhookSecret = process.env.RAZORPAY_WEBHOOK_SECRET!;
const rawBody = (req as any).rawBody; // Mandatory: Unmodified raw request buffer
// 1. Verify Cryptographic HMAC Signature
const expectedSignature = crypto
.createHmac('sha256', webhookSecret)
.update(rawBody)
.digest('hex');
if (expectedSignature !== webhookSignature) {
console.error('[SECURITY ALERT] Invalid webhook HMAC signature detected.');
return res.status(400).json({ error: 'Signature verification failure' });
}
const event = req.body;
const paymentId = event.payload.payment.entity.id;
const orderId = event.payload.payment.entity.order_id;
// 2. Distributed Idempotency Lock via Redis (Prevent Double Credit)
const lockAcquired = await redis.set(`lock:payment:${paymentId}`, '1', 'EX', 60, 'NX');
if (!lockAcquired) {
// Duplicate webhook delivery already in progress or completed
return res.status(200).json({ status: 'Webhook already processed' });
}
// 3. Database Transaction with Status State Machine
await prisma.$transaction(async (tx) => {
const order = await tx.order.findUnique({ where: { id: orderId } });
if (!order || order.status === 'PAID') {
return;
}
await tx.order.update({
where: { id: orderId },
data: {
status: 'PAID',
paymentGatewayTxId: paymentId,
paidAt: new Date(),
}
});
await tx.auditLog.create({
data: {
action: 'PAYMENT_VERIFIED_VIA_WEBHOOK',
orderId: orderId,
metadata: { paymentId, amount: event.payload.payment.entity.amount }
}
});
});
return res.status(200).json({ received: true });
}
4. Frontend Security: Content Security Policy (CSP) & Subresource Integrity
Frontend applications are exposed to malicious browser extensions, third-party analytics script compromises, and cross-site scripting (XSS). An enterprise application must enforce a strict, nonce-based Content Security Policy (CSP) and verify all third-party CDNs via Subresource Integrity (SRI).
Production Strict Nonce-Based CSP Header Template
Content-Security-Policy: default-src 'self'; \
script-src 'self' 'nonce-RANDOM_BASE64_NONCE' https://checkout.razorpay.com; \
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; \
font-src 'self' https://fonts.gstatic.com; \
img-src 'self' data: https://cyberfactsecurity.com; \
connect-src 'self' https://api.cyberfactsecurity.com https://lumberjack.razorpay.com; \
frame-src https://api.razorpay.com; \
object-src 'none'; \
base-uri 'self'; \
form-action 'self'; \
frame-ancestors 'none'; \
block-all-mixed-content; \
upgrade-insecure-requests;
5. Performance Benchmarks: Astro vs. Next.js vs. Vanilla SPA
| Architecture Metric | Next.js 15 (SSR + App Router) | Astro v5+ (Islands Architecture) | Create React App (SPA) |
|---|---|---|---|
| Initial JS Payload | 180 KB - 450 KB | 0 KB - 25 KB | 350 KB - 1.2 MB |
| Largest Contentful Paint (LCP) | 1.4s - 2.2s | 0.4s - 0.7s | 2.5s - 4.8s |
| Interaction to Next Paint (INP) | 90ms - 180ms | < 35ms | 220ms - 450ms |
| Server Memory Footprint (10k req/s) | 1.8 GB | 220 MB (Bun/Static) | N/A (Client heavy) |
| SEO Indexation Reliability | High | Flawless (Static First) | Poor / Prone to Crawl Gaps |
6. Engaging Cyberfact Security for Enterprise Web Engineering
Cyberfact Security does not merely audit codeβour engineering division architects and builds mission-critical, ultra-fast, and hardened web platforms for enterprises across India.
Our Web Engineering Specializations:
- Custom E-Commerce & SaaS Platforms: Sub-second catalog browsing, high-concurrency checkout pipelines, and custom admin portals.
- Enterprise Web Migration: Porting bloated legacy Next.js / WordPress platforms to hardened Astro + Elysia/Node.js stacks.
- Continuous Security Hardening: Baking automated SAST, DAST, and CSP policies into your CI/CD delivery pipelines.
Connect directly with Founder & Principal Architect Saket Choudhary on WhatsApp (+91 82520 02914) to discuss scoping your enterprise web application.
Founder and Lead Security Architect at Cyberfact Security. Specializing in offensive penetration testing (VAPT), distributed cloud architectures, and hardened full-stack engineering for high-growth enterprises.
Initiate a Technical Audit or Custom Engineering Scope
Cyberfact Security delivers certified VAPT audits, source code reviews, and enterprise software engineering for institutions across India. Direct technical engagements with Founder Saket Choudhary.




