Skip to content
Zeni Study
  • Pages
    • Learn Python In 7 Days
      • Day 1 : Variable + if/else
      • Day 2: Loops
      • Day 3 : Array + String
      • Day 4 — Functions
      • Day 5 — Dictionaries - Hashmap
      • Day 6 — Files & Errors
      • Day 7 — Mini Project & Programmer Thinking
    • Machine Coding:
      • Day 1 — Bank account + Wallet :
      • Day 2 : RateLimiter + seat booking
      • Day 3 : Library Management + Classroom Attendance System
      • Day 4 : Bank account and notification system.
      • Day 5 : Key-value and payment processor.
      • Day 6 : Discount engine + Seat booking( in depth)
      • Day 7: Parking lot System :
    • Machine coding extended:
      • Day 7.5 — Parking Lot (Constraint-Heavy Variant)
      • Day 8 : Order + Payment System
      • Day 8 — Extension Round (Mid-Interview Change)
      • Day 9 — Ticket Booking with Expiry (Simulated Time)
      • Day 9 — Extension Round (Seat Lock Ownership + Forced Unlock)
    • SQL + DB Thinking course
      • Day 1 — Tables, Rows & Thinking in Data
      • Day 2 — Relationships & Foreign Keys (Thinking in Connections)
      • Day 3 — Filtering, Aggregation & Answering Data Questions
      • Day 4 — JOINs (Combining Tables the Right Way)
      • Day 5 — Subqueries, EXISTS & NOT EXISTS (Thinking in Layers)
      • Day 6 — Indexes, Constraints & How Databases Think
      • Day 7 — Full SQL Interview Simulation (SDE-1 Ready)
      • Extended Day 1 — Core Business Systems (Deep Practice)
      • Extended Day 2 — Booking & Platform Systems (High-Depth Practice)
      • Extended Day 3 — Content & Learning Platforms (Capstone Practice)
    • LLD: Java
      • DAY 1 — Core Foundations (SDE-2 Level)
      • DAY 2 — State, Time & Domain Correctness
      • DAY 3 — Extensibility & Failure Handling (SDE-2 Core Signal)
      • DAY 4 — Concurrency, Scheduling & Consistency (SDE-2 Critical)
      • DAY 5 — Workflow Design & Config-Driven Systems (SDE-2+)
      • DAY 6 — Eventing & Usage-Based Systems (Advanced SDE-2)
      • icon picker
        DAY 7 — Interview Simulation (Hard, Production-Grade)
      • Hidden Edge Cases Interviewers Expect (Day-wise)
      • Detailed Testing file:
    • Assignment:
      • If else Practice Set

DAY 7 — Interview Simulation (Hard, Production-Grade)

This is it. ​Day 7 is a full interview-simulation day — these problems are hard on purpose and are extremely close to what strong companies ask for final machine-coding / depth rounds.
If you can do Day 7 well, you are solid SDE-2 and competitive for SDE-3.

⚫ DAY 7 — Interview Simulation (Hard, Production-Grade)

Today tests:
Rule engines
Rolling time windows
Idempotency
Failure handling
Backoff + DLQ
Clear abstractions under pressure

✅ Problem 1: Payment Rule Engine (Rolling Window + Rule Chaining)

📌 Problem Statement

Design a payment rule engine to validate transactions before execution.
This system enforces multiple rules:
KYC-based limits
Rolling time-window limits
Extensible rule chaining

Functional Requirements

validate(transaction) → allow / reject
Multiple rules apply
All rules must pass
Rules are independent and pluggable

Rules to Implement (Initial)

Rule 1️⃣: KYC Limit Rule

If user is NOT_KYC
Max ₹20,000 per transaction

Rule 2️⃣: Rolling 24-hour Limit

Total amount sent by user in last 24 hours ≤ ₹100,000

Example

User: U1 (NOT_KYC)
Transaction: ₹25,000 → ❌ rejected

User: U2 (KYC)
Last 24h total: ₹90,000
New txn: ₹15,000 → ❌ rejected

🧩 Java Interfaces (DO NOT MODIFY)

public enum KycStatus {
KYC,
NOT_KYC
}
public class Transaction {
public final String userId;
public final long amount;
public final long timestamp;
public final KycStatus kycStatus;

public Transaction(String userId, long amount, long timestamp, KycStatus kycStatus) {
this.userId = userId;
this.amount = amount;
this.timestamp = timestamp;
this.kycStatus = kycStatus;
}
}
public interface Rule {
boolean validate(Transaction txn);
}
import java.util.List;

public interface PaymentRuleEngine {
boolean validate(Transaction txn);
}

🧪 Driver Code (Auto Tests + Rolling Window)

public class PaymentRuleEngineTest {

public static void main(String[] args) throws Exception {
PaymentRuleEngine engine = new DefaultPaymentRuleEngine(
List.of(
new KycLimitRule(),
new RollingWindowLimitRule(100_000, 24 * 60 * 60 * 1000)
)
);

long now = System.currentTimeMillis();

Transaction t1 = new Transaction("U1", 25_000, now, KycStatus.NOT_KYC);
assert !engine.validate(t1);

Transaction t2 = new Transaction("U2", 60_000, now, KycStatus.KYC);
Transaction t3 = new Transaction("U2", 50_000, now + 1000, KycStatus.KYC);

assert engine.validate(t2);
assert !engine.validate(t3);

Thread.sleep(100);
Transaction t4 = new Transaction("U2", 40_000, now + 2000, KycStatus.KYC);
assert engine.validate(t4);

System.out.println("✅ PaymentRuleEngine tests passed");
}
}

🎯 What Interviewer Evaluates

Rolling window logic
Rule independence
Extensibility (easy to add rules)
No shared mutable chaos

✅ Problem 2: Retry Queue with Backoff & DLQ

📌 Problem Statement

Design a retry queue system that:
Retries failed tasks
Uses exponential backoff
Moves tasks to DLQ after max attempts

Functional Requirements

submit(task)
Failed tasks retry automatically
Max retries = configurable
After max retries → DLQ
Task executed exactly once per attempt

Example

Task fails 3 times
maxRetries = 2
→ goes to DLQ

🧩 Java Interfaces (DO NOT MODIFY)

public interface Task {
boolean execute(); // return true = success
String getId();
}
public interface RetryQueue {
void submit(Task task);
int getDlqSize();
}

🧪 Driver Code (Auto Tests + Failure Handling)

import java.util.concurrent.atomic.AtomicInteger;

public class RetryQueueTest {

public static void main(String[] args) throws Exception {
RetryQueue queue = new InMemoryRetryQueue(2, 500);

AtomicInteger attempts = new AtomicInteger(0);

Task failingTask = new Task() {
@Override
public boolean execute() {
attempts.incrementAndGet();
return false;
}

@Override
public String getId() {
return "task1";
}
};

queue.submit(failingTask);

Thread.sleep(3000);

assert attempts.get() == 3; // initial + 2 retries
assert queue.getDlqSize() == 1;

System.out.println("✅ RetryQueue tests passed");
}
}

🎯 What Interviewer Evaluates

Retry correctness
Backoff implementation
DLQ handling
Threading discipline

🧠 Day 7 Takeaways (Very Important)

If you completed Day 7 properly, you can now:
Build rule engines
Handle time-based rolling windows
Design reliable retry systems
Explain trade-offs clearly under pressure
This is strong SDE-2 → SDE-3 readiness.

🏁 Course Summary (What You Achieved)

In 7 days, you practiced:
14 interview-grade machine coding problems
Real backend patterns (not toy LLD)
Concurrency, workflows, retries, rule engines
Clean Java with tests
This course is far stronger than most paid LLD courses.

🚀 What I Can Do Next (Pick One)

1️⃣ Convert this into a full interview playbook 2️⃣ Add hidden edge cases interviewers usually test verbally 3️⃣ Provide ideal reference implementations (step-by-step) 4️⃣ Simulate a 90-minute real interview (I act as interviewer)
Just tell me how you want to continue 👊
 
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.