VAYULearn
Colour theme
Investigate a failure
VAYU Learn

Data Architecture & Reliability

Data Pipeline Failure Scenarios

Retries • Idempotency • Duplication (What Actually Works in Production)

Data Architecture & ReliabilityKafka & Streaming
Figure - Failure Recovery in Distributed Data Pipelines

In distributed systems, failures are unavoidable. The real challenge is whether retries, duplicates, and recovery logic preserve system correctness or amplify instability.

Reliable systems are not the ones that avoid failure — they are the ones that recover without corrupting data.

Distributed systems do not fail gracefully.

They:

  • retry endlessly
  • duplicate data
  • partially succeed
  • corrupt state silently

And most pipelines are not designed to survive any of it.

A lot of data engineering content teaches:

  • Kafka
  • Spark
  • Airflow
  • streaming architectures

Very little teaches:

👉 what happens when those systems start failing under real production pressure.

This blog is about that reality.

Not theory.

Not toy examples.

Not “hello world” pipelines.

We’ll break down:

  • retry storms
  • duplicate events
  • partial writes
  • poison messages
  • out-of-order processing
  • idempotency strategies

using practical production-style examples.


TL;DR

  • Failures are guaranteed in distributed systems
  • Retries can fix or amplify failures
  • Duplicate events are unavoidable
  • Idempotency is mandatory
  • Reliability is engineered, not configured
Systems don’t fail once.
They fail repeatedly until you design for it.

🧱 1. Why Distributed Pipelines Fail

A modern pipeline is not one system.

It is:

API → Kafka → Stream Processing → DB → Cache → Warehouse → ML Models

Every layer can fail independently.

Common failure sources

Most systems fail not because of one catastrophic bug.

They fail because:

  • small failures compound
  • retries amplify pressure
  • state becomes inconsistent
Reliability problems usually begin as tiny delays.

💥 2. Failure Scenario #1 — Retry Storms

Retries look harmless.

Until they destroy your infrastructure.

Real Production Scenario

Imagine:

  • Kafka consumer processes payment events
  • PostgreSQL becomes temporarily slow
  • consumers start retrying aggressively

❌ Bad Retry Logic

from kafka import KafkaConsumer
import psycopg2

consumer = KafkaConsumer(
"payments",
bootstrap_servers="localhost:9092",
group_id="payment-group"
)
conn = psycopg2.connect(...)
for msg in consumer:
try:
process_payment(msg.value)
except Exception:
process_payment(msg.value) # BAD RETRY

Why This Fails

If DB latency spikes:

retry → more DB load
→ more latency
→ more retries
→ cascading failure

You didn’t recover the system.

You accelerated the outage.

✅ Real Production Pattern — Exponential Backoff

import time
import random

MAX_RETRIES = 5

def retry_with_backoff(fn):
for attempt in range(MAX_RETRIES):
try:
return fn()
except Exception as e:
wait = (2 ** attempt) + random.uniform(0, 1)
time.sleep(wait)

raise Exception("Max retries exceeded")

Why This Works

Instead of overwhelming the DB instantly:

  • retries spread over time
  • pressure decreases
  • downstream systems recover
Retries are traffic multipliers.
Bad retries become denial-of-service attacks.

🌊 2.5 Failure Scenario — Backpressure Collapse

Retries are not the real problem.

Unbounded pressure is.

Real Production Scenario

Suppose:

  • Kafka consumers process events faster than PostgreSQL can write
  • queue depth starts increasing
  • retry logic adds even more load

Now:

  • consumers fall behind
  • memory usage spikes
  • downstream latency explodes
  • the entire pipeline destabilizes

What Engineers Expect

temporary slowdown → temporary recovery

What Actually Happens

slowdown
→ queue growth
→ retries
→ more pressure
→ resource exhaustion
→ cascading outage

Why This Happens

Distributed systems fail through:

  • pressure propagation
  • not isolated component failure

✅ Real Production Pattern — Backpressure Control

1. Bounded Concurrency

Instead of unlimited processing:

MAX_INFLIGHT = 100

semaphore = asyncio.Semaphore(MAX_INFLIGHT)

👉 cap active work.

2. Consumer Throttling

When downstream latency spikes:

  • slow consumption intentionally
  • reduce retry rates
  • allow recovery time

3. Queue Depth Monitoring

Mature systems monitor:

  • Kafka lag
  • queue growth
  • retry volume
  • processing latency

Queue growth is often the earliest outage signal.

4. Circuit Breakers

if db_latency > threshold:
reject_requests()

Sometimes protecting the system means:
👉 refusing work temporarily.

Reliable systems are not infinitely scalable.
They are carefully pressure-controlled.

💥 3. Failure Scenario #2 — Duplicate Events

This is one of the most misunderstood realities in data engineering.

Duplicates are not rare.

They are inevitable.

Real Production Scenario

Consumer:

  1. processes event
  2. writes to DB
  3. crashes before committing offset

Kafka assumes:
👉 message was never processed

So it sends it again.

Result

same event processed twice

Real-World Impact

❌ Naive Consumer

def process_order(order):
cursor.execute("""
INSERT INTO orders(order_id, amount)
VALUES (%s, %s)
"""
, (order["id"], order["amount"]))

If event replays:
👉 duplicate order inserted


🧠 4. Idempotency — The Most Important Reliability Concept

Idempotency means:

👉 processing the same event multiple times produces the same result.

✅ Real Production Solution

Database Constraint:

CREATE TABLE orders (
order_id VARCHAR PRIMARY KEY,
amount NUMERIC,
created_at TIMESTAMP
);

Consumer Logic

def process_order(order):

cursor.execute("""
INSERT INTO orders(order_id, amount)
VALUES (%s, %s)
ON CONFLICT (order_id)
DO NOTHING
"""
, (order["id"], order["amount"]))

Now:

  • replayed events become harmless
  • retries are safe
  • duplicates don’t corrupt state
You do not eliminate duplicates.
You make duplicates safe.

🔑 4.5 Idempotency Across Services

Database constraints alone are not enough.

Modern systems often involve:

  • payment providers
  • external APIs
  • multiple microservices
  • asynchronous retries

Real Production Scenario

A payment request times out:

{
"payment_id": "txn_8472",
"amount": 250
}

Client assumes failure.
Client retries request.

But:
👉 original payment may have already succeeded.

Without idempotency:

  • customer gets charged twice

✅ Real Production Pattern — Idempotency Keys

Clients generate unique request IDs:

POST /payments
Idempotency-Key: txn_8472

Server stores processed keys:

if redis.exists(idempotency_key):
return cached_response()

process_payment()

redis.set(
idempotency_key,
response,
ex=86400
)

Why Redis TTL Matters

Deduplication stores cannot grow forever.

Production systems usually:

  • expire keys after hours/days
  • balance storage cost vs replay safety
  • tune TTL based on business risk

Important Reality

Idempotency boundaries matter.

A request may be:

  • idempotent inside one service
  • duplicated across another
  • replayed asynchronously later

True reliability requires:
👉 end-to-end idempotency design.

Idempotency is not a database feature.
It is a system-wide contract.


💥 5. Failure Scenario #3 — Partial Failure

This is where systems become dangerous.

Real Scenario

Pipeline:

  1. save order to DB
  2. send confirmation email
  3. update analytics

❌ Problem

save_order(order)
send_email(order)
update_analytics(order)

Suppose:

  • DB write succeeds
  • email fails
  • analytics never updates

Now:

  • customer has order
  • no confirmation sent
  • analytics inconsistent

👉 Partial success = silent corruption

✅ Real Production Pattern — Transaction + Outbox

This is widely used in production systems.

Step 1 — Write Both Events Atomically

BEGIN;
INSERT INTO orders VALUES (...);
INSERT INTO outbox_events VALUES (
'order_created',
'{"order_id":123}'
);
COMMIT;

Step 2 — Separate Worker Publishes Events

events = fetch_unpublished_events()
for event in events:
kafka_producer.send("orders", event.payload)
mark_as_published(event.id)

Why This Works

If Kafka fails:

  • DB still consistent
  • event remains in outbox
  • retry later safely
Reliability often comes from decoupling systems.

💥 6. Failure Scenario #4 — Out-of-Order Events

Distributed systems do not guarantee perfect ordering.

Especially at scale.

Real Scenario

User account events:

Event A → Create account
Event B → Upgrade account

But due to retries/networking:

Event B arrives first

Result

upgrade fails because account does not exist

✅ Real Production Pattern — Event Versioning

def process_event(event):
current_version
= get_current_version(event.user_id)
if event.version <= current_version:
return
apply_event(event)

Why This Matters

Without versioning:

  • stale events overwrite fresh state
  • distributed systems become inconsistent
Time ordering is an illusion in distributed systems.

💥 7. Failure Scenario #5 — Poison Messages

One malformed event can stop an entire pipeline.

Real Scenario

data = json.loads(msg.value)

Suppose message:

{
"user_id":
}

Malformed JSON.

Consumer crashes repeatedly.

Kafka keeps replaying same message.

Pipeline becomes permanently stuck.

✅ Real Production Pattern — Dead Letter Queue (DLQ)

try:
process_message(msg)

except Exception as e:

kafka_producer.send(
"dead_letter_queue",
msg.value
)

DLQ Benefits

  • pipeline continues processing
  • bad events isolated
  • debugging easier

What Mature Teams Do

DLQ messages are:

  • monitored
  • replayed manually
  • audited
One bad message should not stop your business.

🔁 7.5 Replay Strategy — The Hidden Disaster

Most teams think replaying events is easy.

It is not.

Large-scale replay is one of the most dangerous operations in distributed systems.

Real Production Scenario

Suppose:

  • a bug corrupts 3 days of events
  • team decides to replay Kafka topics
  • millions of messages flood downstream systems

Now:

  • databases overload
  • retries spike
  • duplicate processing explodes
  • historical bugs reappear

Replay systems can create:
👉 replay storms.

✅ What Mature Teams Do

Controlled Replay

Instead of replaying at full speed:

  • throttle replay throughput
  • isolate replay consumers
  • protect downstream systems

Replay Isolation

Production traffic and replay traffic should not compete.

Mature systems often use:

  • separate consumer groups
  • replay clusters
  • isolated queues

Schema Compatibility Checks

Old events may not match:

  • current schemas
  • current business rules
  • current validation logic

This is where:
👉 schema evolution becomes critical.

Replay Auditing

Before replaying:

  • validate event ranges
  • verify corruption scope
  • snapshot critical state

Because replaying corrupted history:
👉 re-corrupts the system.

Recovery operations are often more dangerous than the original outage.


⏱️ 8. Latency vs Correctness Trade-Off

Every retry adds latency.

Example

Now:
👉 one failed request = 750ms+

Real Engineering Decision

Should system:

  • fail fast?
  • retry?
  • degrade gracefully?

Different systems choose differently.

Real-time systems are defined by trade-offs.

💸 9. The Hidden Cost of Reliability

Reliable systems cost more.

Reliability Adds

Most engineers underestimate:
👉 operational complexity

Reliability is not a feature.
It is an infrastructure tax.

🛑 10. When NOT to Retry

Not every error should retry.

❌ Never Retry

✅ Retry Only

Retrying bad input just repeats failure faster.

🔧 11. Production Reliability Checklist

Before deploying any pipeline:

Ask:

  • Is processing idempotent?
  • What happens on duplicate events?
  • What happens if Kafka replays messages?
  • What happens if downstream systems slow down?
  • Can one bad message stop the pipeline?
  • Are retries bounded?
  • Is ordering guaranteed?

If you cannot answer these:
👉 your pipeline is not production-ready.


💣 12. Unpopular Truth

Most pipelines fail because:

  • engineers optimize for happy paths
  • failure handling is added later
  • retries are naive
  • state consistency is ignored
Failure handling is not “extra engineering.”
Failure handling IS the system.

🧠 13. Mental Model

Reliable pipeline =

Events
+ State
+ Retry Behavior
+ Failure Recovery

Failures become catastrophic when:
👉 retry logic amplifies instability.

A distributed system is only as reliable as its recovery behavior.

⚠️ 13.5 The Myth of “Exactly Once”

One of the biggest misconceptions in distributed systems is:

“Exactly once processing” means duplicates cannot happen.

In reality:
👉 most systems only provide transport-level guarantees.

Kafka’s exactly-once semantics can guarantee:

  • transactional producer writes
  • coordinated offset commits

But they cannot guarantee:

  • external API behavior
  • email delivery
  • database side effects
  • third-party integrations

Real Production Reality

Suppose:

  1. Kafka message processed
  2. payment API charged customer
  3. consumer crashes before offset commit

Kafka replays message.

Result:
👉 payment API may charge customer again.

Important Distinction

Transport exactly-once:

message delivery guarantees

≠

Business exactly-once:

real-world side effects happen once

Most production systems actually aim for:

✅ Effectively Once Processing

Meaning:

  • duplicates may occur internally
  • but final business state remains correct

This is achieved through:

  • idempotency
  • deduplication
  • transactional boundaries
  • replay-safe operations

“Exactly once” is often marketing.

Correct recovery behavior matters far more.


🔧 Debugging These Failures in Practice

If you’re hitting errors like these in production — Airflow failures, Spark OOM,Kafka SSL issues — I built a tool to help.

Paste your broken code + error logs into Vayu and get back:

→ Exact root cause

→ Before/After code fix

→ Confidence score (HIGH/MEDIUM/LOW)

Free to try at vayufix.com

No signup needed for first 3 fixes.


🎯 14. Conclusion

Production systems:

  • retry
  • replay
  • duplicate
  • reorder
  • partially fail

This is normal.

The goal is not preventing failure.

The goal is:
👉 surviving failure without corrupting data.

🔥 Final Law

You don’t build reliable systems by avoiding failure.
You build them by recovering correctly.

🔥 Next in Series

⚠️ Real-Time System Failures — Latency, Drift, and Chaos

Next, we move beyond retries and duplication into something even more dangerous:

👉 systems that are technically “running” but operationally broken.

We’ll break down:

  • how latency silently destroys real-time guarantees
  • why stale features lead to incorrect ML decisions
  • how delayed processing creates cascading system drift
  • and why chaos in distributed systems spreads faster than engineers expect
Real-time systems rarely fail instantly.
They slowly drift away from correctness.

🔔 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.

💬 Comment Below:

What’s the worst pipeline failure you’ve seen?

  • retry storms?
  • duplicate data?
  • poisoned queues?
  • partial failures?

Or answer this:

👉 Do you trust your retry logic in production?


🏷️ Tags

#DataEngineering #Kafka #DistributedSystems #SystemDesign #Streaming #BigData #DataArchitecture