Stream Gatherers in Java: The Stream API Finally Learned to Window, Scan, and Fold

Since Java 8, the Stream API has had an asymmetry: terminal operations were extensible — collect(Collector) lets you define any summary you like — but intermediate operations were a fixed menu. If you wanted windows, running totals, or distinct-by-key in the middle of a pipeline, you either broke out of the pipeline into a loop, or bent a Collector into doing an intermediate operation’s job. Stream Gatherers close that gap. Stream.gather(Gatherer) is to intermediate operations what collect(Collector) is to terminal operations — that framing is JEP 485’s own, and it is the fastest way to understand the feature. ...

2026-11-16 · 19 min · Ramesh

Sliding Window: The Pattern Behind Every Substring Question

The two-pointer playbook introduced the sliding window as one pattern among five. This post gives it the full treatment, because it is the pattern interviewers escalate through: the Easy fixed-size version, the Medium variable-size version, and the Hard frequency-constrained version are the same loop with a different constraint. Learn the loop once and the escalation is just a harder rule to maintain. The loop is: a window [l, r] where r expands every step and l shrinks only until the window satisfies the constraint again. The window is always valid when the shrink loop finishes — that invariant is the whole technique. And it is O(n) for a reason you can state in one sentence: l and r only ever move right, so each index enters the window once and leaves it once. No index is ever revisited, no matter how nested the code looks. I checked the bound empirically: across 2,000 random strings, the total shrink steps in the longest-substring loop never exceeded n. ...

2026-11-15 · 11 min · Ramesh

Cyclic Sort: The O(n) Trick Behind "Find the Missing Number"

Cyclic sort is the highest-ROI pattern you’ve never been taught by name. The entire technique is one invariant: when the values come from a known range, every value belongs at its own index — so put it there. Value v goes to index v (for ranges starting at 0) or index v - 1 (for ranges starting at 1). After one placement pass, whatever sits at the wrong index is the answer: the missing number, the duplicate, the first gap. ...

2026-11-13 · 11 min · Ramesh

Bulkheads in Spring Boot: Stop One Slow Dependency From Sinking the Service

A ship stays afloat when one compartment floods because bulkheads — the watertight walls between sections — keep the water in one place. Your service has the same problem in reverse: one slow dependency floods the shared thread pool, and everything else drowns with it. A payment provider that takes 2 seconds instead of 200 milliseconds doesn’t just make payments slow. It occupies every request thread until the pool is full, and then your health endpoint, your login page, and your fast internal calls all queue behind it. The service isn’t broken. It’s busy — on someone else’s problem. ...

2026-11-08 · 12 min · Ramesh

@Transactional: The 5 Traps That Silently Lose Your Data

@Transactional is the most trusted annotation in Spring Boot — and the most quietly misunderstood. It looks like one annotation doing one job: wrap this method in a transaction. In practice it is a proxy, a set of defaults inherited from EJB, and a handful of hints to Hibernate, and each of those has a sharp edge. None of the five traps below throws an error at the point where you make the mistake. They all fail silently, in production, weeks later. ...

2026-11-07 · 13 min · Ramesh