Cloud Hosting FaaS & Serverless

What is serverless computing and how do Cloudflare Workers compare to AWS Lambda?

Serverless (FaaS) runs individual functions on-demand without managing servers. Cloudflare Workers run at the network edge (<1ms cold start, 300+ global PoPs) while AWS Lambda runs in specific regions (100ms-1s cold start). For Indian developers, Cloudflare Workers offer better latency and simpler pricing; Lambda offers deeper AWS service integration.

DETAILED EXPLANATION:
Serverless execution model:
Traditional server: Process runs 24/7, idle 95% of time, pays for idle
Serverless function: Starts when triggered, runs for milliseconds, shuts down
Pay for: Actual execution time (microseconds), not idle time

When serverless SAVES money:
Webhook processor: 1,000 webhooks/day, each takes 100ms
Serverless cost: 1,000 x 100ms = 100 seconds compute/day
AWS Lambda: ~Rs 0.01/day (essentially free)
Equivalent 24/7 VPS: Rs 500-1,500/month

When serverless is EXPENSIVE:
API with 100,000 requests/day, each 200ms
Lambda: 100,000 x 200ms = 20,000 seconds compute/day x 30 = 600,000 seconds/month
Lambda cost: Rs 2,500+/month vs VPS Rs 500-1,500/month with better performance

Cloudflare Workers advantages:
- <1ms cold start (no JVM spin-up, runs V8 Isolates)
- Runs at 300+ global edge locations simultaneously
- Free tier: 100,000 requests/day
- Built-in KV store, R2 object storage, Durable Objects
- Simple JavaScript/TypeScript/Python (Rust/WASM also supported)

AWS Lambda advantages:
- 15-minute function timeout (Cloudflare Workers: 30 seconds for paid)
- Access to full AWS ecosystem (RDS, S3, SQS, SNS, DynamoDB)
- VPC support (private network access)
- More memory options (up to 10 GB)
- Established for complex backend workflows

India-specific comparison:
Cloudflare Workers:
Nearest edge: India has multiple PoPs
Latency to Indian users: <10ms
No separate India region needed

AWS Lambda:
Mumbai region (ap-south-1): Good latency for India
Cold start: 100-1000ms depending on runtime
Cost: Rs 0.0000166 per 100ms execution

STEP-BY-STEP - Cloudflare Workers for Indian web application:

1. Setup:
npm install -g wrangler
wrangler login

2. Create worker project:
wrangler init india-api
cd india-api

3. worker.js - INR Currency API example:
export default {
async fetch(request, env) {
const url = new URL(request.url);

// CORS headers for Indian web apps
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Content-Type": "application/json"
};

// Route: GET /api/gst-calculator
if (url.pathname === "/api/gst-calculator") {
const amount = parseFloat(url.searchParams.get("amount") || "0");
const rate = parseFloat(url.searchParams.get("rate") || "18");

const gstAmount = amount * (rate / 100);
const total = amount + gstAmount;

return new Response(JSON.stringify({
base_amount: amount,
gst_rate: rate,
gst_amount: gstAmount.toFixed(2),
total: total.toFixed(2),
cgst: (gstAmount / 2).toFixed(2),
sgst: (gstAmount / 2).toFixed(2)
}), { headers: corsHeaders });
}

// Route: POST /api/pincode-lookup
if (url.pathname === "/api/pincode-lookup" && request.method === "POST") {
const { pincode } = await request.json();
// Lookup from KV store (pre-loaded with India pincodes)
const location = await env.PINCODE_KV.get(pincode);
if (location) {
return new Response(location, { headers: corsHeaders });
}
return new Response(JSON.stringify({ error: "Pincode not found" }), {
status: 404, headers: corsHeaders
});
}

return new Response("Not Found", { status: 404 });
}
};

4. wrangler.toml:
name = "india-api"
main = "worker.js"
compatibility_date = "2024-01-01"

kv_namespaces = [
{ binding = "PINCODE_KV", id = "YOUR_KV_NAMESPACE_ID" }
]

5. Deploy:
wrangler deploy

URL: https://india-api.yoursubdomain.workers.dev

REAL EXAMPLES:
Indian e-commerce GST calculation worker:
Request: GET https://api.yourdomain.com/gst?amount=10000&state=MH&category=electronics
Response (< 5ms, served from Mumbai Cloudflare PoP):
{
"amount": 10000,
"gst_rate": 18,
"igst": 1800, // different state
"cgst": 0,
"sgst": 0,
"total": 11800
}

Pincode-to-state lookup worker:
Load 100,000 Indian pincodes into Cloudflare KV
Each lookup: <2ms from Cloudflare edge
vs database query: 50-200ms from VPS

FLOW:
Indian user browser -> Cloudflare Edge (nearest Indian PoP, <10ms) -> Worker executes in V8 Isolate -> Response returned < 20ms total
vs
Indian user browser -> DNS -> Connect Quest VPS -> Node.js API -> Response (50-100ms)

KEY POINTS:
- Cloudflare Workers free tier (100k requests/day) sufficient for most Indian SME APIs
- Workers KV excellent for caching India pincode/GST rate/IFSC data
- For database-backed APIs, use Cloudflare D1 (SQLite) or call Connect Quest VPS origin
- Workers Cron Triggers replace cron jobs for lightweight scheduled tasks

COMMON MISTAKES:
- Using Workers for CPU-intensive tasks (30-second limit, designed for I/O-bound tasks)
- Not handling CORS for Indian mobile apps calling Workers API
- Missing error handling (Worker errors return opaque 500 to browser)

QUICK FIX:
Worker returning 500: Check wrangler tail (real-time log stream)
wrangler tail india-api (see all requests and errors in real-time)

DIFFICULTY: Intermediate
RELATED: Cloud Hosting, API Hosting, CDN, SaaS Architecture, Connect Quest Hosting

Need more help? Our experts are available 24/7.

Visit ConnectQuest → 📞 +91 2269711150
Serving North East India
Assam · Guwahati Meghalaya · Shillong Nagaland · Kohima Arunachal Pradesh · Itanagar Manipur · Imphal Tripura · Agartala Mizoram · Aizawl Sikkim · Gangtok
Professor Conquest Connect Quest AI Assistant
Press Enter to send • Response time: 10-15 seconds