VAYULearn
Colour theme
Investigate a failure
VAYU Learn

Kafka & Streaming

🇮🇳How Indian Startups Handle Real-Time Data at Scale

Zepto • Swiggy • Razorpay - Speed, Cost, and Reality

Kafka & StreamingData Architecture & Reliability

Real-time is not a feature — it’s a cost commitment.

Figure - Real-Time System Trade-Offs (Speed vs Cost vs Accuracy)

Indian startups design data systems under strict latency and cost constraints, where improving one dimension often comes at the expense of another.

You don’t design real-time systems for perfection — you design them for acceptable trade-offs under pressure.

TL;DR

  • Real-time systems are built under latency + cost constraints, not ideal architectures
  • Streaming is used surgically, not everywhere
  • Systems are hybrid (batch + streaming) by necessity
  • The hardest problems are state, spikes, and silent failures
  • Trade-offs are explicit: speed vs accuracy vs cost
These systems are not elegant — they are resilient under pressure.

🚨 Introduction — This Is Not Silicon Valley

Most architecture blogs assume:

  • infinite compute
  • perfect pipelines
  • clean abstractions

Indian startups operate in:

  • tight cost margins
  • unpredictable spikes
  • real-world SLAs

Examples:

  • Zepto → 10-minute delivery
  • Swiggy → real-time logistics
  • Razorpay → financial transactions

The reality:

👉 You don’t design for elegance
👉 You design for latency, cost, and failure

If your system only works in ideal conditions, it doesn’t work.

🧠 1. Core Idea — Real-Time Where It Matters

Beginners think:

👉 “Make everything real-time”

Reality:

👉 Only critical paths are real-time

System ComponentModePaymentsreal-timeMatching / dispatchreal-timeRecommendationsnear real-timeAnalyticsbatch

👉 This reduces:

  • cost
  • complexity
  • failure surface
Real-time is expensive. Use it only where latency changes outcomes.

🧱 2. Architecture Overview

Event Sources (Orders • Payments • GPS • App Events)
↓
Ingestion Layer (Kafka / Event Streams)
↓
Stream Processing (Flink / Spark Streaming)
↓
State Layer (Cache / Feature Store / DB)
↓
Serving Layer (APIs / Models)
↓
Real-Time Decisions
(Dispatch • Pricing • Fraud Detection)

📌 Key Insight

  • events = input
  • state = memory
  • decisions = output

⚠️ Where This Architecture Actually Fails

This diagram looks clean. Production is not.

Hidden complexities:

  • Kafka does not guarantee processing order across partitions
  • Stream jobs must handle duplicate events (idempotency)
  • State stores must handle partial failures + recovery
  • Retries can cause event replay storms

💥 Real Example

A simple retry bug can cause:

  • duplicate payments
  • double rider assignments
  • inconsistent state across services

🧠 Insight

The hard part is not data flow.

👉 It is correctness under failure

Real-time systems are not pipelines — they are decision engines with memory.

⏱️ 3. Latency Budget - Where Your Milliseconds Go

A “real-time system” is a chain of strict latency constraints.

Example SLA: 100ms total

  • ingestion → 5–10ms (Kafka write + network)
  • stream processing → 20–40ms
  • state lookup (Redis) → 5–15ms
  • model inference → 10–25ms
  • API response → 10–20ms

🚨 Reality Check

  • If Redis p99 > 20ms → SLA breaks
  • If Kafka lag > 1–2s → decisions become stale
  • If model inference spikes → cascading delays

👉 You are only as fast as your slowest component

🧠 Insight

Real-time systems are not “fast”

👉 they are tightly budgeted systems with no slack


⚙️ 4. How It Actually Works

Step 1: Event Ingestion

Events include:

  • orders
  • rider location
  • payment requests

👉 Flow through Kafka-like systems

Step 2: Stream Processing

  • joins
  • aggregations
  • windowing

👉 produces real-time signals

Step 3: State Layer (Most Critical)

  • Redis
  • feature stores
  • databases

👉 stores current system state

Without state:

👉 system becomes stateless → wrong decisions

Streams move data. State makes it useful.

Step 4: Serving Layer

  • APIs
  • ML models

Step 5: Decision Layer

  • assign rider
  • calculate price
  • approve payment

👉 all under milliseconds


⚠️ 5. Where Systems Break (Real Failure Modes)

5.1 Traffic Spikes

  • sudden demand surge
  • ingestion overload

👉 causes:

  • lag
  • delayed decisions

5.2 Backpressure

  • processing < ingestion

👉 queues grow → system slows

5.3 Data Loss

  • dropped events
  • partial failures

👉 incorrect decisions

5.4 State Inconsistency

  • stale cache
  • missing updates

👉 wrong outputs

5.5 Latency Violations

  • slow processing
  • delayed APIs

👉 degraded user experience

Real-time systems fail quietly before they fail visibly.

💥 Failure Cascade - How One Delay Breaks Everything

A single delay doesn’t stay isolated.

It cascades.

  1. ingestion lag increases
  2. processing falls behind
  3. state becomes stale
  4. decisions become incorrect
  5. user experience degrades

Real-time systems don’t fail instantly - they degrade silently.

💥 Failure Cascade (System Reality)

ingestion lag ↑
→ processing delay ↑
→ state becomes stale
→ decisions become incorrect
→ retries increase load
→ system overload worsens

👉 feedback loop → system collapse

🧠 Insight

Failures in real-time systems are not linear.

👉 they are amplified by feedback loops


⚖️ 6. Trade-Offs (Senior-Level Thinking)

Latency vs Cost

  • lower latency → higher infra cost

Accuracy vs Speed

  • faster decisions → approximate results

Streaming vs Batch

  • streaming → complex
  • batch → stable

Simplicity vs Scalability

  • simple systems break early
  • complex systems are hard to maintain
Every millisecond saved costs money and complexity.

💸 The Hidden Cost of Real-Time Systems

Real-time systems are not just harder — they are more expensive in every dimension.

Cost doesn’t come from one place:

  • Compute → always-on processing (no batching efficiency)
  • Storage → state management (Redis, feature stores)
  • Network → continuous event flow
  • Engineering → debugging distributed systems
A batch pipeline runs once.
A real-time system never stops running.

At scale:

  • 10ms latency improvement can increase infra cost by 2–5x
  • Over-streaming simple pipelines can cost more than the business value they generate

🌍 7. Real-World Constraints

💰 Cost

  • streaming infra is expensive
  • caching vs recompute decisions

📈 Scale

  • millions of events per minute

⏱️ Latency

  • decisions must be instant

🔧 Operations

  • monitoring
  • debugging
  • recovery
Systems are designed under constraints — not preferences.

🧪 8. Real-World Case Studies — Systems Under Pressure

🛒 Zepto Deep Dive — Real-Time Matching Under Pressure

🎯 Problem

Assign a delivery partner within < 100ms under:

  • high concurrency
  • constantly changing rider locations
  • inventory constraints

⚙️ Actual System Design (Simplified but Realistic)

Step 1: Event Trigger

  • order placed → event pushed to Kafka

Step 2: Candidate Selection

  • query nearby riders from geo-index (Redis / Elastic / custom index)
  • radius-based filtering (e.g., 2–3 km)

Trade-off:
👉 Exact nearest neighbor is too slow
👉 Use approximate geo queries

Step 3: Scoring Function
Each rider scored based on:

  • distance
  • current load
  • delivery SLA risk

👉 Precomputed features stored in state layer (Redis)

Step 4: Assignment

  • best candidate selected
  • assignment written back as event

⚠️ Where It Breaks (Real Issues)

1. Stale Location Data

  • rider GPS delayed by even 2–3 seconds
    👉 wrong assignment

2. Hotspot Overload

  • too many orders in same area
    👉 same riders queried repeatedly
    👉 Redis becomes bottleneck

3. Race Conditions

  • multiple orders assign same rider
    👉 duplicate allocation

🧠 Critical Design Decisions

  • Use approximate nearest neighbor, not exact
  • Accept slightly suboptimal matches
  • Prefer fast + good enough over perfect

⚖️ Trade-Off

🔥 Insight

The system is not optimizing for best delivery.
It is optimizing for:

👉 fast enough decisions under chaos


🍔 Swiggy — Real-Time Logistics Optimization

🎯 Problem

Manage thousands of concurrent deliveries while continuously optimizing routes under:

  • changing traffic conditions
  • restaurant delays
  • rider availability

⚙️ System

Event Inputs:

  • orders
  • restaurant prep status
  • rider location

Processing Model:

  • orders are micro-batched (2–5 second windows)
  • small batches allow:
  • better route grouping
  • reduced per-order computation cost

👉 pure real-time (per-event) is too expensive and unstable
👉 batching introduces slight delay but improves global efficiency

Optimization Loop:

  • assign riders
  • recompute routes continuously
  • update ETAs in near real-time

⚠️ Where It Breaks

  • Late Events
    → delayed restaurant updates
    → incorrect routing decisions
  • Batch Boundary Effects
    → orders falling into different windows
    → suboptimal grouping
  • Peak Load
    → batch size increases under pressure
    → latency creeps up → cascading delays

🧠 Critical Design Decision

👉 Use micro-batching instead of pure streaming

This trades:

  • slight latency increase (seconds)
    for
  • significantly better route efficiency + lower cost

⚖️ Trade-Off

🔥 Insight

The system is not optimizing for instant decisions.

👉 It is optimizing for globally efficient decisions under continuous change


💳 Razorpay — Real-Time Fraud Detection

🎯 Problem

Detect fraudulent transactions within strict latency limits (<100ms) while:

  • minimizing false positives
  • maintaining high approval rates

⚙️ System

Trigger:

  • every transaction generates an event

Decision Flow:

  1. Feature Lookup
  • user history
  • device signals
  • behavioral patterns

👉 pulled from feature store / Redis
👉 must stay <10–15ms p99

2. Rule Engine

  • deterministic checks
  • known fraud patterns

3. ML Scoring

  • risk score computed in real-time

4. Decision

  • approve / block / flag

⚠️ Where It Breaks

  • Slow Feature Store
    → latency spike >20ms
    → total SLA exceeded
    → transaction fails or times out
  • Missing Features
    → incomplete context
    → incorrect scoring
  • Stale Data
    → outdated user behavior
    → false positives / negatives

🧠 Critical Design Decision

👉 Precompute as much as possible in batch pipelines
👉 Use real-time only for final scoring + incremental signals

⚖️ Trade-Off

Different companies. Same constraint: decisions must be fast enough, not perfect.

🔍 9. Hidden Reality — Why Most Real-Time Systems Fail

Failures are rarely due to tools.

They come from:

  • poor state management
  • unclear ownership
  • unrealistic latency assumptions

What actually happens:

  • events arrive late
  • pipelines lag
  • state drifts

👉 decisions become silently incorrect

The most dangerous failure is not crashing — it is being wrong at scale.

🧠 10. Mental Model

Real-time system =

👉 Events + State + Decisions

Break it down:

  • events → input
  • state → memory
  • decisions → output
Without state, real-time systems are blind.

🧨 11. Common Misconceptions

❌ “Everything should be real-time”
❌ “Kafka solves scalability”
❌ “Streaming replaces batch”

Reality:

  • hybrid systems win
  • design > tools
  • constraints drive architecture
Tools don’t solve problems — thinking does.

🛑 When Real-Time Is a Bad Decision

Do NOT build real-time systems if:

  • decisions tolerate > 1 minute delay
  • users don’t act instantly
  • data arrives in batches anyway
  • cost sensitivity is high

🚨 Common Bad Use Cases

❌ real-time dashboards no one monitors
❌ streaming ETL replacing simple batch jobs
❌ live metrics with no operational action

💸 Cost Reality

Real-time systems:

  • run 24/7
  • require constant compute
  • increase debugging complexity

👉 You are paying continuous cost for intermittent value

🧠 Rule

If the business decision is not real-time:

👉 the system should not be real-time

🧨 The $10K/Month Mistake (Real Anti-Pattern)

A very common startup failure:

Problem
A team builds:

  • real-time dashboards (updates every second)
  • streaming pipelines (Kafka + Flink)
  • low-latency infra

Reality

  • business checks dashboard once per day
  • decisions are not time-sensitive
  • no action is taken in real-time

Result

  • infra cost explodes (Kafka + compute + storage)
  • engineering time wasted debugging pipelines
  • zero business impact

Typical cost breakdown:

  • Kafka cluster → $2k–5k/month
  • Stream processing → $3k–8k/month
  • State stores (Redis / DB) → $1k–3k/month

👉 Total: $5k–15k/month for no reason

🧠 What Should Have Been Done

A simple batch system:

  • runs every 15 minutes or 1 hour
  • costs ~90% less
  • delivers the same business value

🚨 Lesson

If no decision changes in real-time:

👉 real-time is not a feature — it is waste

Most startups don’t have a scaling problem.
They have a decision-speed mismatch problem.


✅ Real-Time System Design Checklist

Before building a real-time system, ask:

  • What decisions actually require low latency?
  • What is the acceptable delay?
  • What is the cost budget?
  • What happens when data is late?
  • What happens when state is wrong?
  • Can this be batch instead?

If you can’t answer these, don’t build a real-time system.


Most real-time pipelines in startups are unnecessary.
They exist because engineers want to use streaming -
not because the business needs it.

🎯 Conclusion

These companies don’t win because they use better tools.

They win because they:

  • design under constraints
  • prioritize critical paths
  • accept trade-offs early

This leads to:

  • resilient systems
  • scalable decisions
  • real-world performance

Good engineers build pipelines. Great engineers choose not to build them.

🔥 Final Law

The best system is not the fastest — 
it is the one that
works under pressure.

Most systems don’t fail because they are slow.

👉 They fail because they are fast, expensive, and unnecessary


🔥 Next in Series

💥 What Happens When a Kafka Pipeline Breaks in Production

Next, we break down:

  • lag
  • backpressure
  • data loss
  • recovery strategies

🔔 Follow for More

Follow TheDataForge for high-signal deep dives on Spark, Kafka, Streaming, Lakehouse, and real-world data engineering — no fluff, only engineering truth.

⚡️Let’s connect — I post daily Big Data & Spark insights at DataForgeX on X.

💬 Final Thought:

If your system only works when nothing goes wrong:

👉 it doesn’t work


🏷️ Tags

#DataEngineering #RealTimeData #Streaming #SystemDesign #Kafka #BigData #Scalability #EventDriven