<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tahmeer Pasha on Medium]]></title>
        <description><![CDATA[Stories by Tahmeer Pasha on Medium]]></description>
        <link>https://medium.com/@tahmeer?source=rss-92a2689ba681------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4N9nNWD4U5QmizdUa9vgyQ.jpeg</url>
            <title>Stories by Tahmeer Pasha on Medium</title>
            <link>https://medium.com/@tahmeer?source=rss-92a2689ba681------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 17:51:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tahmeer/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Pelatro Software Engineer Interview Experience (September 2026)]]></title>
            <link>https://medium.com/@tahmeer/pelatro-software-engineer-interview-experience-september-2026-78962455bb7c?source=rss-92a2689ba681------2</link>
            <guid isPermaLink="false">https://medium.com/p/78962455bb7c</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[interview-experience]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[pelatro]]></category>
            <dc:creator><![CDATA[Tahmeer Pasha]]></dc:creator>
            <pubDate>Mon, 26 Oct 2026 11:35:08 GMT</pubDate>
            <atom:updated>2026-10-26T11:35:08.408Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently interviewed for the <strong>Engineer — Development </strong>role at Pelatro, Bengaluru. The process consisted of four rounds covering Core Java, problem-solving, SQL, debugging, project experience, and behavioral questions.</p><h3>Interview Timeline</h3><ul><li><strong>Day 1 — Onsite:</strong> First two technical rounds at the company’s office.</li><li><strong>Day 2 — Online:</strong> Hiring Manager and HR rounds, conducted online on separate days, one day after another.</li></ul><h3>Round 1: Technical Interview (Onsite)</h3><p>This round focused on Core Java, coding, SQL, debugging, and logical reasoning.</p><p>Questions included:</p><ul><li>Write an SQL query to identify records that were created or updated.</li><li>How would you debug a thread that runs for a long time?</li><li>Explain Set, HashMap, and the contract between equals() and hashCode().</li><li>Sort a string of numbers based on the sum of digits at odd positions, without using Collections or another array.</li><li>Solve a horse-and-rope logical puzzle.</li><li>Why do we need abstract classes when interfaces can have methods with implementations since Java 8?</li></ul><p><strong>Result:</strong> Cleared.</p><h3>Round 2: Technical Interview (Onsite)</h3><p>This round focused on logical problem-solving and validating my technical experience.</p><p>Questions included:</p><ul><li>Given two chessboard positions, determine whether they are the same color.</li><li>Questions based on my resume and previous project experience.</li></ul><p><strong>Result:</strong> Cleared.</p><h3>Round 3: Hiring Manager (Online)</h3><p>This round focused on practical engineering scenarios, project ownership, debugging, and problem-solving.</p><p>Questions included:</p><ul><li>Explain how I achieved an 80% reduction in root-cause analysis (RCA) issues.</li><li>Why was I looking for a job change?</li><li>An API is expected to respond in 5 ms but takes 5 seconds. How would I investigate the issue step by step?</li><li>Find the maximum product of three integers in an array, considering negative numbers as well.</li></ul><p><strong>Result:</strong> Cleared.</p><h3>Round 4: HR Interview (Online)</h3><p>The final round covered behavioral scenarios and general HR discussions.</p><p>Topics included:</p><ul><li>How would you handle a release when two out of four team members are on leave?</li><li>Compensation expectations.</li><li>Notice period and availability.</li><li>General questions about my experience and background.</li></ul><p><strong>Result:</strong> Selected.</p><h3>Key Takeaways</h3><ul><li><strong>Focus strongly on Core Java:</strong> Be comfortable with collections, HashMap, equals() and hashCode(), multithreading, and problem-solving.</li><li><strong>Spring Boot was not a major focus in my interview:</strong> Based on my interview experience, much of the technical discussion centered on Core Java and Pelatro’s own technologies.</li><li><strong>Practice coding problems with constraints:</strong> Some questions restrict the use of built-in data structures, so understand the underlying logic rather than relying only on library methods.</li><li><strong>Prepare your resume thoroughly:</strong> Be ready to explain project decisions, measurable improvements, and your individual contributions.</li><li><strong>Practice debugging and real-world scenarios:</strong> Be able to explain a structured, step-by-step approach instead of jumping straight to a solution.</li><li><strong>Communicate your reasoning clearly:</strong> The interviewer is interested in how you approach a problem, not just the final answer.</li></ul><p>Overall, my experience involved a mix of Core Java fundamentals, coding, logical reasoning, practical debugging, and behavioral questions. For candidates preparing for a similar role, I would prioritize Core Java and problem-solving, while also learning about the company’s technology stack.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78962455bb7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Java Handles Concurrency - Locks, CAS and Optimistic Concurrency]]></title>
            <link>https://medium.com/@tahmeer/how-java-handles-concurrency-locks-cas-and-optimistic-concurrency-ff33ca7df6ab?source=rss-92a2689ba681------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff33ca7df6ab</guid>
            <category><![CDATA[locking-mechanism]]></category>
            <category><![CDATA[pessimistic-locking]]></category>
            <category><![CDATA[optimisitic-locking]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[java-concurrency]]></category>
            <dc:creator><![CDATA[Tahmeer Pasha]]></dc:creator>
            <pubDate>Sat, 05 Sep 2026 04:31:02 GMT</pubDate>
            <atom:updated>2026-09-11T07:41:27.985Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inh_1HTbtkA_HorT9IOU7w.png" /><figcaption>Jist of the entire article</figcaption></figure><h3>How Java Handles Concurrency -Locks, CAS and Optimistic Concurrency</h3><p><em>Part 2 of a two-part series on concurrency and locking in Java</em></p><p>In the previous article, we looked at why concurrency is difficult.</p><p>We started with something as simple as:</p><pre>count++;</pre><p>and discovered that concurrent programming isn’t simply about “running two things at the same time.”</p><p>We have to worry about:</p><ul><li>Race conditions</li><li>Critical sections</li><li>Atomicity</li><li>Visibility</li><li>Instruction reordering</li><li>The Java Memory Model</li><li>Happens-before relationships</li></ul><p>So now comes the interesting part:</p><p><strong>How does Java actually solve these problems?</strong></p><p>Java gives us several tools:</p><pre>synchronized<br>ReentrantLock<br>ReadWriteLock<br>StampedLock<br>volatile<br>AtomicInteger<br>AtomicReference<br>CAS</pre><p>But these aren’t random APIs.</p><p>Each exists because it solves a particular concurrency problem.</p><p>Let’s build our understanding from the simplest mechanism first.</p><h3>1. The Simplest Solution: Don’t Let Two Threads Enter</h3><p>Remember our counter?</p><pre>class Counter {<br>private int count = 0;<br>    public void increment() {<br>        count++;<br>    }<br>}</pre><p>We identified the problem:</p><pre>Thread 1          Thread 2<br>READ 0            READ 0<br>ADD 1             ADD 1<br>WRITE 1           WRITE 1</pre><p>What if we could simply say:</p><blockquote><strong><em>“Only one thread is allowed to execute this critical section at a time.”</em></strong></blockquote><p>Then:</p><pre>Thread 1          Thread 2<br>LOCK<br>  ↓<br>READ 0<br>ADD 1<br>WRITE 1<br>  ↓<br>UNLOCK<br>                  LOCK<br>                    ↓<br>                  READ 1<br>                  ADD 1<br>                  WRITE 2<br>                    ↓<br>                  UNLOCK</pre><p>Now we get:</p><pre>count = 2</pre><p>This is the basic idea behind <strong>pessimistic locking</strong>.</p><p>We assume another thread might interfere, so we prevent it from entering the critical section.</p><p>And Java’s simplest mechanism for doing this is: synchronized</p><h3>2. Synchronized</h3><p>We can fix our counter like this:</p><pre>class Counter {<br>    private int count = 0;<br>    public synchronized void increment() {<br>        count++;<br>    }<br>}</pre><p>That’s it.</p><p>When one thread enters increment():</p><pre>Thread 1<br>    ↓<br>acquire lock<br>    ↓<br>increment()<br>    ↓<br>release lock</pre><p>Another thread trying to enter the same synchronized method has to wait.</p><p>But there’s something more important happening here.</p><p>synchronized isn&#39;t simply saying:</p><blockquote><em>“Only one thread at a time.”</em></blockquote><p>It also establishes <strong>memory synchronization guarantees</strong>.</p><p>That means it helps with both:</p><pre>Mutual exclusion<br>       +<br>Memory visibility<br>       +<br>Ordering guarantees</pre><p>This is why synchronization is much more powerful than simply putting a “lock” around a piece of code.</p><h3>3. What Is Java Actually Locking?</h3><p>This is one of the most important things to understand about synchronized.</p><p>Consider:</p><pre>public synchronized void increment() {<br>    count++;<br>}</pre><p>If increment() is an instance method, the lock is associated with the object instance.</p><p>Conceptually:</p><pre>Counter counter = new Counter();<br>counter.increment();</pre><p>is synchronized using the monitor associated with:</p><pre>counter</pre><p>You can think of it roughly as:</p><pre>public void increment() {<br>    synchronized (this) {<br>        count++;<br>    }<br>}</pre><p>So if two threads have the same Counter object:</p><pre>Thread 1 ──┐<br>           ↓<br>       Counter object<br>           ↑<br>Thread 2 ──┘</pre><p>they compete for the same monitor.</p><p>But if you have:</p><pre>Counter counter1 = new Counter();<br>Counter counter2 = new Counter();</pre><p>then they have different objects and therefore different intrinsic locks.</p><p>That’s an important lesson:</p><blockquote><strong><em>Synchronization only works when the threads coordinate using the same lock.</em></strong></blockquote><h3>4. Synchronized Block</h3><p>You don’t always want to synchronize an entire method.</p><p>You can synchronize only the critical section:</p><pre>public void increment() {<br>  // Some code that doesn&#39;t need locking<br>      synchronized (this) {<br>          count++;<br>      }<br>    // More code<br>}</pre><p>You can also use a dedicated lock object:</p><pre>private final Object lock = new Object();<br><br>public void increment() {<br>    synchronized (lock) {<br>        count++;<br>    }<br>}</pre><p>This is often preferable to exposing this as a synchronization mechanism.</p><p>The general idea is:</p><pre>              Method<br>                │<br>       ┌────────┴────────┐<br>       │                 │<br> Non-critical       Critical section<br>    code                  │<br>                          ↓<br>                    synchronized</pre><p>The smaller the critical section, the less time other threads potentially spend waiting.</p><p>But don’t blindly minimize it either.</p><p>The critical section must contain <strong>all the operations that need to be performed atomically together</strong>.</p><h3>5. What About static synchronized?</h3><p>There’s another interesting case:</p><pre>public static synchronized void doSomething() {<br>}</pre><p>Now we’re dealing with a class-level lock rather than an individual object instance.</p><p>Conceptually:</p><pre>instance synchronized<br>        ↓<br>    this object<br><br><br>static synchronized<br>        ↓<br>    Class object</pre><p>So two different instances can have different instance locks, but a static synchronized method uses the lock associated with the class.</p><h3>6. If synchronized Works, Why Does Java Need ReentrantLock?</h3><p>This is a very reasonable question.</p><p>If we already have:</p><pre>synchronized</pre><p>why introduce another locking mechanism?</p><p>Because sometimes we need <strong>more control over the locking process</strong>.</p><p>That’s where: ReentrantLock comes in.</p><p>Basic usage:</p><pre>private final Lock lock = new ReentrantLock();<br><br>public void increment() {<br>    lock.lock();<br>    try {<br>        count++;<br>    } finally {<br>        lock.unlock();<br>    }<br>}</pre><p>Notice something immediately.</p><p>With synchronized:</p><pre>synchronized (lock) {<br>    // critical section<br>}</pre><p>Java handles releasing the monitor when you leave the block.</p><p>With ReentrantLock:</p><pre>lock.lock();<br>try {<br>    // critical section<br>} finally {<br>    lock.unlock();<br>}</pre><p><strong>You are responsible for releasing it.</strong></p><p>That’s why the finally block is not optional.</p><p>If you forget:</p><pre>lock.unlock();</pre><p>you can leave other threads waiting indefinitely.</p><h3>7. So What Does ReentrantLock Give Us?</h3><p>The main advantage isn’t that it’s “more powerful” in some vague sense.</p><p>It gives us <strong>additional control</strong>.</p><p>For example:</p><p>tryLock()</p><p>Instead of waiting indefinitely:</p><pre>if (lock.tryLock()) {<br>    try {<br>        // critical section<br>    } finally {<br>        lock.unlock();<br>    }<br>}</pre><p>You can attempt to acquire the lock and do something else if it isn’t available.</p><p>That’s useful when waiting isn’t desirable.</p><h3>Interruptible Lock Acquisition</h3><p>You can also do:</p><pre>lock.lockInterruptibly();</pre><p>This allows a thread waiting for the lock to respond to interruption.</p><h3>Fairness</h3><p>You can create a fair lock:</p><pre>Lock lock = new ReentrantLock(true);</pre><p>The idea is that threads waiting for the lock are given a more orderly opportunity to acquire it.</p><p>Fairness can reduce starvation in some situations, although it can come with a performance cost.</p><h3>8. synchronized vs ReentrantLock</h3><p>So which one should you use?</p><p>A useful mental model is:</p><pre>Need basic mutual exclusion?<br>            ↓<br>       synchronized<br><br>Need additional control?<br>            ↓<br>       ReentrantLock</pre><p>For ordinary mutual exclusion, synchronized is often the better starting point.</p><p>Don’t choose ReentrantLock simply because it looks more advanced.</p><h3>9. What If Most Operations Are Reads?</h3><p>Imagine a shared cache.</p><p>Thousands of threads are reading it:</p><pre>READ<br>READ<br>READ<br>READ<br>READ</pre><p>but occasionally someone needs to update it:</p><pre>WRITE</pre><p>If we use a normal exclusive lock, even readers block other readers.</p><p>But readers don’t necessarily interfere with each other.</p><p>That’s where:</p><h3>ReadWriteLock</h3><p>comes in.</p><pre>ReadWriteLock lock = new ReentrantReadWriteLock();<br>lock.readLock().lock();<br>try {<br>    // read<br>} finally {<br>    lock.readLock().unlock();<br>}</pre><p>Multiple readers can hold the read lock simultaneously.</p><p>But a writer needs exclusive access:</p><pre>Reader ─┐<br>Reader ─┼──&gt; Can execute together<br>Reader ─┘<br><br><br>Writer ───&gt; Must execute alone</pre><p>This can make sense when:</p><pre>Reads &gt;&gt;&gt; Writes</pre><p>But there’s an important practical point:</p><blockquote><em>Don’t assume </em><em>ReadWriteLock is automatically faster.</em></blockquote><p>Lock management itself has overhead, and the benefit depends on the workload.</p><p>If writes are frequent or the critical sections are tiny, a normal lock may be perfectly adequate.</p><h3>10. StampedLock</h3><p>Java also provides:</p><pre>StampedLock</pre><p>It supports:</p><ul><li>Read locking</li><li>Write locking</li><li>Optimistic reads</li></ul><p>The optimistic-read part is particularly interesting.</p><p>Instead of immediately acquiring a traditional read lock, a thread can say:</p><blockquote><em>“I’ll read the data, and afterward I’ll check whether someone modified it while I was reading.”</em></blockquote><p>Conceptually:</p><pre>Start optimistic read<br>        ↓<br>    Read data<br>        ↓<br>    Validate<br>        │<br>   ┌────┴────┐<br>   ↓         ↓<br>Valid      Invalid<br>   ↓         ↓<br>Use data   Retry</pre><p>This is our first glimpse of a completely different approach to concurrency.</p><p>Instead of:</p><blockquote><strong><em>Lock first.</em></strong></blockquote><p>we can say:</p><blockquote><strong><em>Proceed and check later.</em></strong></blockquote><p>And that leads us to optimistic concurrency.</p><h3>11. Pessimistic vs Optimistic Locking</h3><p>There are two broad ways to deal with concurrent modifications.</p><h3>Pessimistic</h3><blockquote><em>Assume a conflict is likely.</em></blockquote><p>Therefore:</p><pre>Acquire lock<br>      ↓<br>Do work<br>      ↓<br>Release lock</pre><p>Examples include:</p><pre>synchronized<br>ReentrantLock<br>ReadWriteLock<br>Database row locks</pre><h3>Optimistic</h3><blockquote><em>Assume conflicts are relatively rare.</em></blockquote><p>Therefore:</p><pre>Read<br> ↓<br>Do work<br> ↓<br>Check whether somebody changed it<br> ↓<br>Success OR retry/fail</pre><p>This can avoid making threads wait for a traditional lock.</p><p>But there’s a trade-off.</p><p>If conflicts are extremely common:</p><pre>attempt<br> ↓<br>conflict<br> ↓<br>retry<br> ↓<br>conflict<br> ↓<br>retry<br> ↓<br>conflict</pre><p>optimistic concurrency can become expensive.</p><p>So optimistic doesn’t mean:</p><blockquote><em>“Always faster.”</em></blockquote><p>It means:</p><blockquote><strong><em>“Don’t pay the cost of preventing a conflict unless a conflict actually occurs.”</em></strong></blockquote><h3>12. CAS — Compare And Set</h3><p>One of the most important mechanisms behind optimistic concurrency in Java is:</p><p><strong>CAS — Compare-And-Set.</strong></p><p>Imagine:</p><pre>Current value = 10</pre><p>We want to change it to:</p><pre>11</pre><p>But only if nobody changed it since we read it.</p><p>Conceptually:</p><pre>CAS(<br>    expected = 10,<br>    newValue = 11<br>)</pre><p>If the current value is still 10:</p><pre>10 == expected 10<br>        ↓<br>    SUCCESS<br>        ↓<br>       11</pre><p>But if another thread already changed it:</p><pre>Current = 12<br>Expected = 10</pre><p>then:</p><pre>10 != 12<br>   ↓<br>FAIL</pre><p>No traditional lock was required.</p><h3>13. Atomic Classes</h3><p>Java exposes CAS-based concurrency mechanisms through classes such as:</p><pre>AtomicInteger<br>AtomicLong<br>AtomicReference</pre><p>For example:</p><pre>AtomicInteger counter = new AtomicInteger(0);<br>counter.incrementAndGet();</pre><p>Instead of:</p><pre>count++;</pre><p>we have an atomic operation provided by AtomicInteger.</p><p>Conceptually, the implementation is doing something like:</p><pre>Read current value<br>       ↓<br>Calculate new value<br>       ↓<br>      CAS<br>       ↓<br>Did someone change it?<br>   ┌───┴────┐<br>   ↓        ↓<br>  No       Yes<br>   ↓        ↓<br>Update    Retry</pre><p>This is why atomic classes can perform certain operations without a traditional mutual-exclusion lock.</p><h3>14. volatile — The One Beginners Usually Misunderstand</h3><p>Now we need to talk about: volatile</p><p>because it is frequently confused with synchronized.</p><p>Suppose we have:</p><pre>private volatile boolean running = true;</pre><p>volatile gives us important <strong>visibility and ordering guarantees</strong>.</p><p>When one thread writes:</p><pre>running = false;</pre><p>another thread reading running has the appropriate visibility guarantees provided by volatile semantics.</p><p>But here’s the catch.</p><p>This:</p><pre>volatile int count;<br>count++;</pre><p>does <strong>not</strong> turn count++ into an atomic operation.</p><p>Why?</p><p>Because:</p><pre>count++</pre><p>is still:</p><pre>READ<br> ↓<br>ADD<br> ↓<br>WRITE</pre><p>volatile doesn&#39;t magically combine those three operations into one atomic read-modify-write operation.</p><p>So remember:</p><pre>volatile<br>   ↓<br>Visibility + ordering<br>_________________________________<br><br>AtomicInteger<br>   ↓<br>Atomic operations<br>_______________________________<br><br>synchronized / Lock<br>   ↓<br>Mutual exclusion + memory synchronization</pre><p>Different tools solve different problems.</p><h3>15. Optimistic Locking Isn’t Only About CAS</h3><p>Here’s where the concept gets particularly interesting for backend developers.</p><p>Imagine a database row:</p><pre>Account<br>-------------------------<br>id       = 101<br>balance  = 1000<br>version  = 5</pre><p>Two requests read it.</p><pre>Request A              Request B<br>balance = 1000         balance = 1000<br>version = 5            version = 5</pre><p>Suppose A updates first.</p><p>The database becomes:</p><pre>balance = 900<br>version = 6</pre><p>Now B tries to update based on the old version:</p><pre>Expected version = 5</pre><p>But the database says:</p><pre>Actual version = 6</pre><p>The update fails.</p><p>Conceptually:</p><pre>UPDATE account<br>SET balance = ...,<br>    version = version + 1<br>WHERE id = 101<br>AND version = 5;</pre><p>The important idea is:</p><blockquote><strong><em>Update the resource only if the version you originally read is still the current version.</em></strong></blockquote><p>That’s version-based optimistic concurrency.</p><h3>16. Optimistic Locking with JPA</h3><p>If you’re working with Java backend applications, you’ve probably encountered:</p><pre>@Version<br>private Long version;</pre><p>For example:</p><pre>@Entity<br>class Account {<br>    @Id<br>    private Long id;<br>    private BigDecimal balance;<br>    @Version<br>    private Long version;<br>}</pre><p>JPA can use the version field to detect concurrent modifications.</p><p>Conceptually:</p><pre>Read entity<br>    ↓<br>version = 5<br>    ↓<br>Modify entity<br>    ↓<br>UPDATE ... WHERE version = 5<br>    ↓<br>Did update succeed?<br>     │<br> ┌───┴────┐<br> ↓        ↓<br>YES      NO<br> ↓        ↓<br>Success  Conflict</pre><p>This is the same fundamental idea as CAS:</p><blockquote>“Change this value, but only if nobody changed what I originally observed”</blockquote><p>The mechanism is different, but the underlying idea is remarkably similar.</p><h3>17. Java Locks vs Database Locks</h3><p>Now we can connect everything back to the distinction we briefly discussed earlier.</p><p>Suppose you have two instances of your Spring Boot application:</p><pre>             Database<br>           /           \<br>          /             \<br>      JVM 1             JVM 2<br>       │                  │<br>    Thread A           Thread B</pre><p>If Thread A does:</p><pre>synchronized (lock) {<br>    // update account<br>}</pre><p>that lock exists inside <strong>JVM 1</strong>.</p><p>JVM 2 knows absolutely nothing about it.</p><p>It can happily execute:</p><pre>synchronized (lock) {<br>    // update account<br>}</pre><p>using its own lock.</p><p>So:</p><blockquote><strong><em>A Java lock coordinates threads within the synchronization scope of that lock.</em></strong></blockquote><p>It does not automatically coordinate different JVMs.</p><p>Database locking operates at a different level:</p><pre>JVM 1 ──────┐<br>            ↓<br>         Database<br>            ↑<br>JVM 2 ──────┘</pre><p>That’s why choosing the right synchronization mechanism depends heavily on <strong>where the shared state actually lives</strong>.</p><h3>18. Locks Come With Their Own Problems</h3><p>We’ve spent this entire series talking about how locks help us.</p><p>But locks aren’t free.</p><p>They introduce their own problems.</p><h3>Lock Contention</h3><p>Imagine:</p><pre>100 threads<br>     ↓<br>   LOCK<br>     ↓<br>1 thread works<br>99 threads wait</pre><p>If your critical section takes a long time, performance can suffer badly.</p><h3>Deadlock</h3><p>Consider two locks:</p><pre>Thread 1:<br>Lock A<br>  ↓<br>Waiting for Lock B</pre><p>and:</p><pre>Thread 2:<br>Lock B<br>  ↓<br>Waiting for Lock A</pre><p>Now:</p><pre>Thread 1 → waiting for Thread 2<br>Thread 2 → waiting for Thread 1</pre><p>Nobody can proceed.</p><p>That’s a deadlock.</p><h3>Starvation</h3><p>A thread may repeatedly fail to get the resource it needs because other threads keep winning access.</p><p>So synchronization introduces another responsibility:</p><blockquote><strong><em>Don’t just make the code correct. Make the locking strategy sensible.</em></strong></blockquote><h3>19. So Which One Should You Use?</h3><p>Here’s the mental model I’d keep:</p><pre>Do I have shared mutable state?<br>          │<br>         NO<br>          ↓<br>      No lock needed<br><br><br>          YES<br>           │<br>           ↓<br>Can I avoid sharing it?<br>           │<br>           ├── YES → Prefer immutability /<br>           │         thread confinement<br>           │<br>           ↓<br>        Need synchronization<br>           │<br>           ↓<br>Are conflicts frequent?<br>      ┌────┴────┐<br>     YES       NO<br>      │          │<br>      ↓          ↓<br>Pessimistic   Optimistic<br>      │          │<br>      │          ├── CAS<br>      │          └── Versioning<br>      │<br>      ├── synchronized<br>      ├── ReentrantLock<br>      ├── ReadWriteLock<br>      └── StampedLock</pre><p>But there’s one more question worth asking before reaching for any of these:</p><blockquote><strong><em>Can I design the shared state away entirely?</em></strong></blockquote><p>Often, avoiding shared mutable state is simpler than trying to synchronize it correctly.</p><p>Immutability, thread confinement, message passing, and other designs can reduce the amount of locking you need.</p><h3>20. The Bigger Picture</h3><p>Let’s go back to where we started.</p><p>We had:</p><pre>count++;</pre><p>and discovered that concurrent execution can break our assumptions.</p><p>We then learned that concurrency requires us to reason about:</p><pre>Atomicity<br>Visibility<br>Ordering</pre><p>Java provides several mechanisms to help us establish those guarantees:</p><pre>                    Java Concurrency<br>                           │<br>          ┌────────────────┼────────────────┐<br>          │                │                │<br>       Locks            Atomics         Visibility<br>          │                │                │<br>    synchronized          CAS           volatile<br>    ReentrantLock         │<br>    ReadWriteLock         │<br>    StampedLock      AtomicInteger<br>                      AtomicLong<br>                      AtomicReference</pre><p>And at a higher level:</p><pre>                CONCURRENCY CONTROL<br>                       │<br>              ┌────────┴────────┐<br>              │                 │<br>        Pessimistic         Optimistic<br>              │                 │<br>        &quot;Lock first&quot;        &quot;Check later&quot;<br>              │                 │<br>          Java Locks          CAS<br>          DB Locks            Versioning</pre><p>The important thing isn’t memorizing all these classes.</p><p>It’s understanding <strong>why they exist</strong>.</p><h3>Final Takeaway</h3><p>When you encounter concurrent code, don’t immediately ask:</p><blockquote><em>“Should I use </em><em>synchronized or </em><em>ReentrantLock?&quot;</em></blockquote><p>Start with better questions:</p><p><strong>1. What state is shared?</strong></p><p><strong>2. What operations need to be atomic?</strong></p><p><strong>3. Do threads need to see each other’s changes?</strong></p><p><strong>4. What ordering guarantees are required?</strong></p><p><strong>5. Where does the shared state live — inside the JVM or somewhere external like a database?</strong></p><p><strong>6. Are conflicts frequent or rare?</strong></p><p>Only then should you choose the mechanism.</p><p>Because concurrency isn’t really about locks.</p><p><strong>Locks are just one tool for controlling concurrency.</strong></p><p>The real skill is understanding the problem well enough to know <strong>when you need one, what it should protect, and when you shouldn’t use one at all.</strong></p><h3>The mental model to remember</h3><pre>Shared mutable state<br>        ↓<br>Concurrent access<br>        ↓<br>Potential race condition<br>        ↓<br>Need coordination<br>        ↓<br>Choose based on the problem<br>        │<br>        ├── Mutual exclusion<br>        │       ↓<br>        │   synchronized<br>        │   ReentrantLock<br>        │<br>        ├── Many readers<br>        │       ↓<br>        │   ReadWriteLock<br>        │<br>        ├── Optimistic reads<br>        │       ↓<br>        │   StampedLock<br>        │<br>        ├── Atomic state updates<br>        │       ↓<br>        │   CAS / Atomic*<br>        │<br>        └── Database concurrency<br>                ↓<br>            Locking / Versioning</pre><p><strong>Understand the problem first. The API comes second.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff33ca7df6ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Before You Learn Java Locks, Understand Concurrency First]]></title>
            <link>https://medium.com/@tahmeer/before-you-learn-java-locks-understand-concurrency-first-9dd9115d11d3?source=rss-92a2689ba681------2</link>
            <guid isPermaLink="false">https://medium.com/p/9dd9115d11d3</guid>
            <category><![CDATA[locks]]></category>
            <category><![CDATA[java-concurrency]]></category>
            <category><![CDATA[java-lock-mechanisms]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Tahmeer Pasha]]></dc:creator>
            <pubDate>Sat, 29 Aug 2026 10:51:12 GMT</pubDate>
            <atom:updated>2026-08-29T10:53:47.992Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QYftg8iVDy1qi0dje3KZIA.png" /><figcaption>Understand the concurrency problem</figcaption></figure><p><em>Part 1 of a two-part series on concurrency and locking in Java</em></p><p>If you’ve worked with Java for a while, you’ve probably seen code like this:</p><pre>synchronized void increment() {<br>    count++;<br>}</pre><p>You may know that synchronized makes the code &quot;thread-safe.&quot;</p><p>But have you ever stopped and asked:</p><p><strong>What problem is </strong><strong>synchronized actually solving?</strong></p><p>Why can’t two threads simply execute the same piece of code at the same time?</p><p>And why does Java need concepts like synchronized, volatile, locks, atomic variables, and the Java Memory Model in the first place?</p><p>Before learning the solutions, let’s understand the problem.</p><h3>Let’s Start With a Simple Counter</h3><p>Consider this class:</p><pre>class Counter {<br>  private int count = 0;<br>    public void increment() {<br>        count++;<br>    }<br>    public int getCount() {<br>        return count;<br>    }<br>}</pre><p>Now imagine two threads calling increment().</p><pre>Counter counter = new Counter();<br>Thread t1 = new Thread(counter::increment);<br>Thread t2 = new Thread(counter::increment);<br>t1.start();<br>t2.start();</pre><p>What should the final value of count be?</p><p>Obviously: 2, right?</p><p>There were two calls to increment().</p><p>But under concurrent execution, you can end up with: 1</p><p>How?</p><p>The answer is hiding inside this innocent-looking statement:</p><pre>count++;</pre><h3>count++ Is Not One Operation</h3><p>We tend to read:</p><pre>count++;</pre><p>as:</p><blockquote><em>“Increase count by one.”</em></blockquote><p>But conceptually, the computer has to do something closer to:</p><pre>1. Read count<br>2. Add 1<br>3. Write the result back</pre><p>So if count is currently 0:</p><pre>READ  → 0<br>ADD   → 1<br>WRITE → 1</pre><p>Now imagine two threads.</p><pre>Thread 1                 Thread 2<br>Read count → 0<br>                         Read count → 0<br>Add 1                    Add 1<br>Write 1<br>                         Write 1</pre><p>Both threads read 0.</p><p>Both calculate 1.</p><p>Both write 1.</p><p>The final result:</p><pre>count = 1</pre><p>One increment has effectively disappeared.</p><p>This is a <strong>race condition</strong>.</p><h3>What Is a Race Condition?</h3><p>A race condition occurs when the correctness of a program depends on the timing or ordering of concurrent operations.</p><p>In our example, the result depends on <strong>how the operations of Thread 1 and Thread 2 are interleaved</strong>.</p><p>If Thread 1 completes its entire operation before Thread 2 starts:</p><pre>Thread 1:<br>READ → ADD → WRITE<br><br>Thread 2:<br>READ → ADD → WRITE</pre><p>Everything works.</p><p>But if their operations interleave:</p><pre>Thread 1:<br>READ<br>Thread 2:<br>READ<br>Thread 1:<br>ADD<br>Thread 2:<br>ADD<br>Thread 1:<br>WRITE<br>Thread 2:<br>WRITE</pre><p>We lose an update.</p><p>And this leads us to an important concept.</p><h3>The Critical Section</h3><p>A <strong>critical section</strong> is a section of code that accesses shared state and must be executed under controlled synchronization to preserve correctness.</p><p>In our example:</p><pre>count++;</pre><p>is part of the critical section.</p><p>Why?</p><p>Because the operation:</p><pre>READ → MODIFY → WRITE</pre><p>needs to behave as one logical unit.</p><p>We don’t want another thread interfering halfway through it.</p><p>This gives us our first requirement for concurrent programming:</p><blockquote><strong><em>Some operations need to be atomic.</em></strong></blockquote><h3>Atomicity Doesn’t Mean “One CPU Instruction”</h3><p>This is where things get slightly more interesting.</p><p>You might think:</p><blockquote><em>“If reading and writing an </em><em>int are atomic, shouldn&#39;t </em><em>count++ also be atomic?&quot;</em></blockquote><p>Not necessarily.</p><p>There is a difference between:</p><p><strong>An atomic operation</strong></p><p>and</p><p><strong>A sequence of atomic operations.</strong></p><p>For example:</p><pre>READ count<br>WRITE count</pre><p>may individually be safe from being partially executed.</p><p>But:</p><pre>READ<br>MODIFY<br>WRITE</pre><p>is a larger operation.</p><p>Another thread can interfere between those steps.</p><p>This is why we often talk about <strong>compound operations</strong> when discussing concurrency.</p><p>The problem isn’t necessarily that a thread can see half-written data.</p><p>The problem is that another thread can interfere with the sequence of operations that should logically happen together.</p><h3>But Race Conditions Aren’t the Only Problem</h3><p>Suppose we fix our counter problem.</p><p>Does that mean we’re done with concurrency?</p><p>Not even close.</p><p>There is another question we need to answer:</p><blockquote><strong><em>When one thread changes something, when does another thread see that change?</em></strong></blockquote><p>Consider this:</p><pre>class Worker {<br>private boolean running = true;<br>    public void stop() {<br>        running = false;<br>    }<br>    public void work() {<br>        while (running) {<br>            // do some work<br>        }<br>    }<br>}</pre><p>Imagine:</p><pre>Thread 1                  Thread 2<br>work()                    stop()<br>while (running)           running = false</pre><p>A human might reason:</p><blockquote><em>Thread 2 changes </em><em>running to </em><em>false, so Thread 1 will eventually see </em><em>false and exit the loop.</em></blockquote><p>But concurrent programs don’t get to rely on such assumptions without the proper memory guarantees.</p><p>This brings us to our second major concurrency problem:</p><h3>Visibility</h3><p>In a multithreaded program, one thread may modify shared state while another thread reads that state.</p><p>We need guarantees about <strong>when that modification becomes visible to the other thread</strong>.</p><p>At a high level, you can think about memory like this:</p><pre>                Main Memory<br>                     │<br>          ┌──────────┴──────────┐<br>          │                     │<br>       Thread 1              Thread 2<br>          │                     │<br>       Local view            Local view</pre><p>Modern CPUs have caches and other mechanisms between the CPU and main memory.</p><p>The JVM and hardware are free to perform optimizations as long as they preserve the required semantics.</p><p>Therefore, writing concurrent code requires more than simply thinking:</p><blockquote><em>“Thread A changed the variable, so Thread B will immediately see it.”</em></blockquote><p>We need synchronization rules that establish that guarantee.</p><h3>And Then There’s Instruction Reordering</h3><p>Now we have another problem.</p><p>Consider:</p><pre>a = 1;<br>b = 2;</pre><p>As a programmer, we naturally think:</p><pre>a = 1<br>    ↓<br>b = 2</pre><p>But modern compilers and CPUs perform optimizations.</p><p>They can reorder operations when doing so doesn’t change the observable behavior of a correctly synchronized single-threaded program.</p><p>For single-threaded code, this is usually invisible.</p><p>For concurrent code, however, another thread may observe operations in ways that don’t match our intuitive source-code ordering unless the appropriate synchronization guarantees exist.</p><p>Consider a simplified example:</p><pre>// Thread 1<br>x = 1;<br>r1 = y;<br><br>// Thread 2<br>y = 1;<br>r2 = x;</pre><p>Without the necessary synchronization, reasoning purely from the order of lines in the source code can be misleading.</p><p>This is one reason concurrent programming is harder than simply:</p><blockquote><em>“Run two methods at the same time.”</em></blockquote><p>There are multiple things we need to reason about.</p><h3>The Three Problems We Need to Solve</h3><p>At this point, we can summarize the major issues.</p><p>When multiple threads interact with shared mutable state, we need to reason about:</p><h3>1. Atomicity</h3><p>Can an operation be interrupted or interleaved with another thread?</p><p>Our count++ example demonstrated this.</p><h3>2. Visibility</h3><p>When one thread changes shared state, when is another thread guaranteed to see that change?</p><p>Our running example demonstrated this.</p><h3>3. Ordering</h3><p>In what order are operations guaranteed to become visible to other threads?</p><p>Instruction reordering makes this particularly important.</p><p>So we have:</p><pre>              CONCURRENCY<br>                  │<br>       ┌──────────┼──────────┐<br>       │          │          │<br>   Atomicity   Visibility   Ordering<br>       │          │          │<br>       ↓          ↓          ↓<br>   &quot;Don&#39;t let   &quot;See what   &quot;See operations<br>    operations   others      in the required<br>    interfere&quot;   changed&quot;    order&quot;</pre><p>And now we have a much better question than:</p><blockquote><em>“How do I make this method thread-safe?”</em></blockquote><p>The real question is:</p><blockquote><strong><em>How do we establish the guarantees our concurrent program needs?</em></strong></blockquote><h3>Enter the Java Memory Model</h3><p>This is where Java’s <strong>Java Memory Model (JMM)</strong> becomes important.</p><p>The JMM defines the rules governing how threads interact through memory.</p><p>You don’t need to memorize the entire specification to understand everyday concurrency.</p><p>One concept is particularly important:</p><h3>Happens-Before</h3><p>The happens-before relationship gives us a way to reason about whether the effects of one operation are guaranteed to be visible to another operation.</p><p>Conceptually:</p><pre>Thread A<br>write shared state<br>       │<br>       │<br> synchronization<br>       │<br>       ▼<br>   happens-before<br>       │<br>       ▼<br>Thread B<br>read shared state</pre><p>If the appropriate happens-before relationship exists, Thread B has the necessary visibility guarantees regarding Thread A’s actions.</p><p>This is one of the fundamental ideas behind Java’s concurrency mechanisms.</p><p>And it brings us back to our original question.</p><h3>So How Do We Solve These Problems?</h3><p>We’ve now seen that concurrent programs can fail because of:</p><pre>Race Conditions<br>       ↓<br>Atomicity problems<br>       ↓ <br>Visibility problems<br>       ↓<br>Ordering problems</pre><p>We need mechanisms that allow threads to coordinate their access to shared state and establish the necessary memory guarantees.</p><p>And Java gives us several.</p><p>For example:</p><pre>synchronized</pre><p>There are also:</p><pre>ReentrantLock<br>ReadWriteLock<br>StampedLock<br>volatile<br>AtomicInteger<br>AtomicReference<br>CAS</pre><p>And these mechanisms don’t all solve exactly the same problem.</p><p>Some provide mutual exclusion.</p><p>Some provide visibility.</p><p>Some use optimistic techniques.</p><p>Some allow multiple readers.</p><p>Some use hardware-supported compare-and-set operations instead of traditional locks.</p><p>Understanding these tools becomes much easier once we understand the problems they’re designed to solve.</p><h3>One Last Thing: Why Not Just Avoid Concurrency?</h3><p>A reasonable question is:</p><blockquote><em>“If concurrency is this complicated, why not just use one thread?”</em></blockquote><p>Because concurrency is extremely useful.</p><p>Modern applications need to:</p><ul><li>Handle multiple requests simultaneously</li><li>Perform background work</li><li>Process messages</li><li>Perform I/O without blocking everything else</li><li>Utilize multiple CPU cores</li><li>Build responsive applications</li><li>Process large workloads efficiently</li></ul><p>The goal isn’t to avoid concurrency.</p><p>The goal is to <strong>control it correctly</strong>.</p><p>And that’s where synchronization mechanisms come in.</p><h3>Where We Go From Here</h3><p>We started with a simple:</p><pre>count++;</pre><p>and discovered that concurrent programming involves much more than two threads executing code simultaneously.</p><p>We encountered:</p><pre>Shared Mutable State<br>        ↓<br>Race Conditions<br>        ↓<br>Critical Sections<br>        ↓<br>Atomicity<br>        ↓<br>Visibility<br>        ↓<br>Instruction Reordering<br>        ↓<br>Java Memory Model<br>        ↓<br>Happens-Before</pre><p>Now we’re ready to understand the tools Java provides to deal with these problems.</p><p>In the next article, we’ll start with the simplest one:</p><pre>synchronized</pre><p>Then we’ll move deeper into Java’s concurrency toolbox:</p><pre>synchronized<br>     ↓<br>ReentrantLock<br>     ↓<br>ReadWriteLock<br>     ↓<br>StampedLock<br>     ↓<br>volatile<br>     ↓<br>CAS<br>     ↓<br>Atomic classes<br>     ↓<br>Optimistic concurrency<br>     ↓<br>Version-based locking</pre><p>The goal isn’t to memorize these APIs.</p><p>It’s to understand <strong>why each one exists, what problem it solves, and when you should actually use it.</strong></p><p><em>This is Part 1. Part 2 will cover how Java actually implements these concurrency mechanisms and how pessimistic and optimistic locking fit into the picture.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9dd9115d11d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Built a Cost-Constrained Postgres to DynamoDB Sync Pipeline for a Production Horse Racing…]]></title>
            <link>https://medium.com/@tahmeer/how-i-built-a-cost-constrained-postgres-to-dynamodb-sync-pipeline-for-a-production-horse-racing-2d2deb2188b6?source=rss-92a2689ba681------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d2deb2188b6</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Tahmeer Pasha]]></dc:creator>
            <pubDate>Thu, 02 Jul 2026 08:12:07 GMT</pubDate>
            <atom:updated>2026-07-02T08:12:07.734Z</atom:updated>
            <content:encoded><![CDATA[<h3>How I Built a Cost-Constrained Postgres to DynamoDB Sync Pipeline for a Production Horse Racing Data Platform</h3><h3>The Problem Was Serious</h3><p>A horse has run 12 races this season. One Lambda fails mid-processing. Suddenly the system counts only 11. In a premiership context, that single missing race is the difference between a horse qualifying or being eliminated from the tournament entirely.</p><p>That’s not a hypothetical. That’s the kind of data correctness failure we were dealing with.</p><p>I work on the backend data platform for a large Australian horse racing company. The platform exposes racing data — horse stats, jockey win percentages, trainer success rates, historical form — to downstream consumers including betting companies and broadcasting networks. The data has to be correct. Wrong data doesn’t just make dashboards look bad. It affects real competitive outcomes.</p><p>The original architecture used a real-time XML processing pipeline: XML files would arrive, Lambdas would process them, and data would flow into DynamoDB which was queried by AppSync APIs downstream. The problem was this pipeline was fragile. When a Lambda failed mid-processing, partial data made it through. Stats got miscalculated. Customers complained. Organizers complained. Developers had to manually go in and fix data.</p><p>The fix was a dedicated reliability layer: a separate platform (let’s call it the Data Platform) that pulled from an upstream historical system containing records going back to 1977, loaded raw data into Postgres, ran business logic through stored procedures, and produced clean, reliable output. My job was to build the pipeline that moved that clean output from Postgres into DynamoDB every morning.</p><p>This post is about the design decisions I made, the constraints I worked under, and what I’d do differently.</p><h3>The Architecture</h3><p>Here’s the full flow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mg6GMkqsbG9e5DqedNqN_g.png" /><figcaption>Pipeline Overview</figcaption></figure><p>The core mechanic is an <strong>iterative loop</strong>: Step Functions calls the Lambda repeatedly. Each invocation reads from Postgres using a last_modified filter, processes a batch of 500 records, writes them to DynamoDB, updates a checkpoint file in S3 with the last processed ID, and returns true if more records remain. When there&#39;s nothing left to process, it returns false and Step Functions stops the execution.</p><p>A full pipeline run — processing 200,000 to 300,000 records — takes around 45 minutes.</p><h3>The Design Decisions</h3><h3>Why Lambda Instead of EC2 or ECS</h3><p>The data this platform serves is consumed by betting and broadcasting companies. Security wasn’t a secondary concern — it was the primary constraint.</p><p>EC2 instances mean attack surface: open ports, patch management, someone owning uptime at 2am. We were a lean team with specific system owners — nobody had bandwidth to own EC2 patching cycles. Serverless meant we could delegate that entire class of problem to AWS and focus on the actual business logic.</p><p>ECS would have worked technically, but it introduced container management complexity the team didn’t want to own. Lambda was the right fit: stateless, event-driven, zero infrastructure to maintain.</p><h3>Why Step Functions Instead of a Single Long-Running Lambda</h3><p>Lambda has a hard 15-minute execution timeout. A full pipeline run takes up to 45 minutes. A single Lambda invocation can’t do this.</p><p>The alternatives were a long-polling ECS task or building retry and continuation logic ourselves inside Lambda. Step Functions gave us orchestration for free — including visual execution history, per-step error visibility, and retry configuration without custom code.</p><p>When something goes wrong, you can open the Step Functions console and see exactly which iteration failed, at what point in the batch, and what the error was. That operational visibility alone was worth it.</p><h3>Why S3 Checkpointing</h3><p>The checkpoint file is simple: a single JSON object in S3.</p><pre>{ &quot;last_seen_id&quot;: 48291 }</pre><p>Every time a Lambda invocation completes a batch, it writes the ID of the last record it processed. If the pipeline stops mid-run for any reason — Lambda timeout because Postgres was under load, a network blip, anything — the next invocation reads this file and picks up exactly where it stopped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*5aH-dR7SW3HanKffDTeyTA.png" /><figcaption>Checkpoint Resumability Flow</figcaption></figure><p>We chose S3 over writing the checkpoint back to DynamoDB or Postgres for three reasons: cost (S3 reads/writes are essentially free at this scale), simplicity (no extra table, no schema to manage), and independence (the checkpoint store doesn’t share fate with either database).</p><p>This saved us multiple full reruns during the months the pipeline was in production.</p><h3>Why EventBridge Instead of a Cron Lambda</h3><p>The team had a design principle: all scheduled triggers live in one place. EventBridge gave us a single audit trail for every scheduled job across the platform. When something runs unexpectedly, or doesn’t run when it should, you have one place to look.</p><p>It also keeps the Lambdas themselves cleaner — they’re just processors, not schedulers. Separation of concerns at the infrastructure level.</p><h3>Why Not Glue ETL or DMS</h3><p>We evaluated both.</p><p>AWS Glue is excellent — for terabytes. Our data was in the range of 50–150GB per table. At that scale, Glue’s pricing model and startup overhead didn’t justify itself. We’d be paying for a system designed for a problem 10x larger than ours.</p><p>DMS (Database Migration Service) is the “right” answer for Postgres-to-DynamoDB migrations if you’re thinking purely about the technology. But DMS requires configuration, replication instance management, and ongoing maintenance. Our team was lean — each system had a specific owner — and we had no one to own a DMS replication instance long-term. Adding that dependency meant adding operational surface area nobody had budget or bandwidth to cover.</p><p>Sometimes the boring AWS-native solution — Lambda, Step Functions, S3 — is the right answer precisely because it fits inside what your team can actually maintain.</p><h3>Why 500 Records Per Batch</h3><p>This came from tuning, not theory.</p><p>When Postgres was under load, read latency would spike. Lambda would wait on slow queries and start approaching its timeout. We needed a batch size small enough that a single invocation could complete reliably even under degraded database performance, but large enough that we weren’t making thousands of Step Functions iterations to get through a full run.</p><p>500 was the number. Your right number will depend on your record size, query complexity, and downstream write latency.</p><h3>The Audit Layer</h3><p>Every record that moves through the pipeline gets appended to a CSV file in S3.</p><p>This sounds unglamorous. It was one of the most practically useful parts of the system.</p><p>The data team reads it to verify that what landed in DynamoDB matches what came out of Postgres. Developers use it when there’s a discrepancy report — instead of querying both databases and diffing manually, you look at the audit file for that day’s run.</p><p>In a domain where wrong data has real competitive consequences, being able to prove what moved, when, and what it contained is not optional. Build the audit layer.</p><h3>When It Actually Failed</h3><p>Lambda timeouts happened. Not often, but they happened — and understanding <em>why</em> requires understanding a deliberate architectural trade-off we made.</p><p>The pipeline provided eventual consistency: most data landed in DynamoDB after each morning’s run. That was acceptable for the bulk of racing stats — horse win percentages, jockey form, trainer records. These update once a day and downstream consumers are fine with that.</p><p>But certain data needed to be correct on every single query. Meet rank — which determines what position a race meet appears at a given day and time — is a good example. For fields like this, waiting until the next morning’s pipeline run wasn’t an option. So AppSync resolvers for that data queried Postgres directly instead of DynamoDB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iyfFXD8Mk4fYhaX6ZEt3aw.png" /><figcaption>Consistency Trade-off</figcaption></figure><p>The cost of that decision was shared load on Postgres. When enough direct AppSync queries hit Postgres simultaneously, read latency for our pipeline queries would spike, and Lambda would occasionally approach its timeout.</p><p>When a timeout occurred, the checkpoint file meant the next Step Functions retry started from the last successfully processed batch, not from zero. The pipeline continued.</p><p>We didn’t need exponential backoff or complex retry strategies because the failure mode was predictable and recoverable at the Step Functions level. Don’t over-engineer retry logic until you understand your actual failure patterns.</p><h3>What I’d Do Differently</h3><p>If I were building this today without the cost, team size, and management constraints, I’d use DMS and build it as a proper data engineering pipeline — Change Data Capture, schema evolution handling, proper dead-letter queues, the works.</p><p>The checkpointing, batching, and retry logic I wrote manually are solved problems in real ETL frameworks. We were doing AWS plumbing where a proper tool existed.</p><p>But under the constraints we had — serverless mandate, lean team, cost ceiling, security requirements — the approach was correct. Engineering decisions aren’t made in a vacuum. The best architecture is the one your team can actually build and operate.</p><h3>Key Takeaways</h3><p><strong>Serverless isn’t just about cost — it’s about operational surface area.</strong> For a lean team with security constraints, removing EC2 from the picture was the right call regardless of price.</p><p><strong>S3 checkpointing is underrated.</strong> One JSON file with a last-seen ID gave us resumability for free. If your pipeline runs longer than a single Lambda timeout, you need something like this.</p><p><strong>Match tooling to data scale.</strong> Glue for GBs is overkill. Step Functions + Lambda loops are unglamorous but they work, they’re cheap, and they’re easy to debug.</p><p><strong>Build the audit layer even when nobody asks for it.</strong> In production systems where data correctness has downstream consequences, the ability to prove what happened is worth more than the 10 lines of code it takes.</p><p><strong>Eventual and strong consistency can coexist in the same system</strong> — but the boundary between them has a cost. In our case, that cost showed up as shared Postgres load. Know where your consistency boundaries are before they show up as production incidents.</p><p><strong>Constraints are design inputs.</strong> Cost ceilings, team size, security mandates — these aren’t obstacles to good architecture. They’re parameters. The goal is the best system within the real constraints, not the theoretically perfect system that nobody can operate.</p><p><em>I’m a backend engineer working with AWS, Java/Spring Boot, and distributed systems. If you found this useful or have questions about the architecture, connect with me on LinkedIn.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d2deb2188b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chargebee Software Engineer Interview Experience]]></title>
            <link>https://medium.com/@tahmeer/chargebee-software-engineer-interview-experience-7bba86436e3e?source=rss-92a2689ba681------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bba86436e3e</guid>
            <category><![CDATA[interview-experience]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Tahmeer Pasha]]></dc:creator>
            <pubDate>Tue, 02 Jun 2026 07:16:38 GMT</pubDate>
            <atom:updated>2026-06-02T07:16:38.301Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently interviewed with Chargebee for a Software Engineer position and wanted to share my experience. Even though I was rejected in the final round, I found the process well-structured and learned quite a few things from it.</p><h3>Recruiter Screening</h3><p>A recruiter reached out to me around two days before the interview. I applied for the role, but I couldn’t attend the initial call. The recruiter called again the night before the interview, explained the entire interview process, and asked me to be present at the office by 8:30 AM.</p><p>One thing I appreciated was the transparency throughout the process. The recruiter clearly explained the rounds, the interviewers involved, and what to expect.</p><p>The entire interview process was completed on the same day.</p><p>The interview took place at a WeWork coworking space.</p><h3>Round 1: Written Assessment</h3><p>The first round was a written test focused on backend and system design fundamentals.</p><p>The questions were roughly around:</p><ol><li>Database schema design</li><li>REST API design</li><li>Designing a concurrent application</li></ol><p>I don’t remember the exact problem statements, but the emphasis was on understanding design concepts and being able to explain your approach.</p><p><strong>Result:</strong> Cleared</p><h3>Round 2: Coding Round</h3><p>This was the only round where working code was expected.</p><p>Questions:</p><ol><li>Longest non-repeating character sequence</li><li>Flatten an array</li><li>Find the 3rd highest salary of an employee (SQL)</li></ol><p>The discussion included time complexity and optimization considerations.</p><p><strong>Result:</strong> Cleared</p><h3>Round 3: Hiring Manager Round</h3><p>This round focused heavily on my professional experience and projects.</p><p>We discussed:</p><ul><li>Project architecture</li><li>Design decisions</li><li>Technical trade-offs</li><li>Challenges faced during implementation</li></ul><p>Towards the end, I was asked to design a rate limiter. Due to time constraints, I provided a high-level design rather than going into implementation details.</p><p>One interesting aspect of this round was that the interviewer was not looking for production-ready code. The focus was on understanding the concept, reasoning through the solution, and communicating the approach clearly.</p><p><strong>Result:</strong> Cleared</p><h3>Round 4: Vice President Round</h3><p>The final round started with a DSA question:</p><ul><li>Design a queue using arrays</li></ul><p>Unfortunately, I wasn’t able to solve it. The interview was scheduled on short notice and I hadn’t revised some of the fundamental concepts recently.</p><p>The discussion then shifted towards my college projects. The VP opened my GitHub profile and asked questions about various repositories, including why some projects were not deployed and decisions made during development.</p><p>Again, the focus was more on understanding and explanation rather than writing complete code.</p><p><strong>Result:</strong> Rejected</p><h3>Feedback</h3><p>The feedback I received was that the questions I asked during the interview were thoughtful and showed curiosity. However, they did not feel I was the right fit for the role at that time.</p><h3>Key Takeaways</h3><ol><li>Fundamentals matter. Even seemingly simple data structures can become stumbling blocks if not revised regularly.</li><li>Communication plays a huge role. Except for the coding round, most of the interview weightage was on understanding concepts, explaining trade-offs, and reasoning through solutions rather than writing working code.</li><li>Be prepared to discuss everything on your resume and GitHub. Interviewers may go deep into projects you built years ago.</li><li>Candidate experience was excellent. Every round included actionable feedback, and the recruiter was transparent throughout the process.</li></ol><p>Overall, despite the rejection, it was a positive interview experience and gave me a clear picture of areas I need to improve before future interviews.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bba86436e3e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I Learned About the Hidden Cost of Database Indexes]]></title>
            <link>https://medium.com/@tahmeer/what-i-learned-about-the-hidden-cost-of-database-indexes-30175a5b61a9?source=rss-92a2689ba681------2</link>
            <guid isPermaLink="false">https://medium.com/p/30175a5b61a9</guid>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[indexing]]></category>
            <dc:creator><![CDATA[Tahmeer Pasha]]></dc:creator>
            <pubDate>Thu, 12 Feb 2026 14:47:30 GMT</pubDate>
            <atom:updated>2026-02-12T14:47:30.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZId2J1OpW5iFQ1SMdIQA1Q.png" /><figcaption>Database indexing</figcaption></figure><p>For a long time, my default reaction to a slow query was:</p><blockquote><em>“Let’s add an index.”</em></blockquote><p>And sometimes that works. Dramatically.</p><p>But while optimizing queries in PostgreSQL recently, I realized something important:</p><p>Indexes are not free.<br>They are trade-offs.</p><p>Here’s what I learned.</p><h3>1. PostgreSQL Optimizes Cost — Not “Speed”</h3><p>When we add an index, we expect the query to become faster.</p><p>But PostgreSQL doesn’t think in terms of “fast” or “slow.”<br>It estimates <strong>cost</strong>.</p><p>When you run:</p><pre>EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 101;</pre><p>The planner compares:</p><ul><li>Sequential scan cost</li><li>Index scan cost</li><li>Random vs sequential I/O</li><li>Estimated row count (cardinality)</li><li>CPU processing cost</li></ul><p>If the index doesn’t reduce estimated cost enough, it won’t be used.</p><p>That was my first realization:<br>Adding an index doesn’t guarantee it will even be picked.</p><h3>2. Cardinality Matters More Than I Thought</h3><p>I used to think:</p><p>“If a column is in the WHERE clause, index it.”</p><p>But the real question is:</p><p>How selective is it?</p><p>Example:</p><pre>SELECT * FROM users WHERE status = &#39;active&#39;;</pre><p>If 90% of users are active:</p><ul><li>The index still has to fetch almost the entire table.</li><li>A sequential scan may be cheaper.</li></ul><p>High cardinality columns (like email or user_id) benefit more from indexing than low cardinality ones (like boolean flags).</p><h3>3. Composite Indexes Changed My Understanding</h3><p>I saw a case like this:</p><pre>SELECT *<br>FROM orders<br>WHERE status = &#39;completed&#39;<br>AND created_at &gt;= NOW() - interval &#39;7 days&#39;;</pre><ul><li>status had only a few distinct values.</li><li>But created_at filtered the dataset heavily.</li></ul><p>Indexing status alone wouldn’t help much.</p><p>Instead, a composite index:</p><pre>CREATE INDEX idx_orders_status_created_at<br>ON orders (status, created_at);</pre><p>reduced execution time significantly.</p><p>The execution plan switched from a sequential scan to a <strong>Bitmap Index Scan</strong>, which batches page fetches to reduce random I/O.</p><p>That’s when I understood:<br>Index design is about aligning with real query patterns — not just adding single-column indexes everywhere.</p><h3>4. Indexes Slow Down Writes</h3><p>This part surprised me more than anything.</p><p>Every index is a separate B-Tree structure.</p><p>For every:</p><ul><li>INSERT</li><li>UPDATE (on indexed column)</li><li>DELETE</li></ul><p>PostgreSQL must also update every index.</p><p>If a table has 5 indexes, one insert becomes 6 write operations.</p><p>For write-heavy systems, this becomes a serious cost.</p><p>So now I ask:</p><p>Is the read improvement worth the write overhead?</p><h3>5. Partial Indexes Are Underrated</h3><p>Instead of indexing an entire column:</p><pre>CREATE INDEX idx_users_status ON users(status);</pre><p>You can sometimes do:</p><pre>CREATE INDEX idx_active_users<br>ON users (id)<br>WHERE status = &#39;active&#39;;</pre><p>Smaller index.<br>Higher selectivity.<br>Lower write cost.</p><p>This was something I hadn’t appreciated enough before.</p><h3>6. Too Many Indexes Can Confuse the Planner</h3><p>More indexes don’t always mean better performance.</p><p>If a table has multiple overlapping indexes, the planner must evaluate many possible plans.</p><p>With stale statistics, it can even choose the wrong one.</p><p>That’s when I understood:</p><p>Indexing is not “set and forget.”<br>It requires monitoring and periodic review.</p><h3>7. When I Now Avoid Indexing</h3><p>I now think twice before adding an index when:</p><ul><li>The table is small</li><li>The column has very low selectivity</li><li>The table is heavily write-focused</li><li>The query runs rarely</li><li>The indexed column changes frequently</li></ul><p>Instead of blindly adding indexes, I start with:</p><pre>EXPLAIN ANALYZE</pre><p>Measure first. Optimize second.</p><p>Final Thought</p><p>I used to see indexes as a quick performance fix.</p><p>Now I see them as a workload decision.</p><p>Each index:</p><ul><li>Speeds up some reads</li><li>Slows down some writes</li><li>Consumes storage</li><li>Adds maintenance overhead</li></ul><p>The goal isn’t to minimize indexes.</p><p>The goal is to have the <strong>right indexes for your workload.</strong></p><p>Still learning. Still experimenting.<br>But this shift in thinking has changed how I approach database performance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30175a5b61a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>