<?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"><channel><title><![CDATA[Angelo Arcillas]]></title><description><![CDATA[Deep dives into software architecture, distributed systems, and real-time engineering. I write practical lessons from building multi-tenant SaaS platforms—cover]]></description><link>https://angeloarcillas.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 02:15:56 GMT</lastBuildDate><atom:link href="https://angeloarcillas.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Why Server Clocks Lie: How Bad Timing Breaks "Latest Wins" Across Servers]]></title><description><![CDATA[Out-of-sync server clocks make now() unreliable for ordering updates. See how clock drift breaks Latest Wins and how counters or ordered logs fix it.]]></description><link>https://angeloarcillas.hashnode.dev/why-server-clocks-lie-how-bad-timing-breaks-latest-wins-across-servers</link><guid isPermaLink="true">https://angeloarcillas.hashnode.dev/why-server-clocks-lie-how-bad-timing-breaks-latest-wins-across-servers</guid><category><![CDATA[distributed systems]]></category><category><![CDATA[Reliability]]></category><category><![CDATA[architecture]]></category><category><![CDATA[software development]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[System Design]]></category><category><![CDATA[backend]]></category><dc:creator><![CDATA[Angelo Arcillas]]></dc:creator><pubDate>Thu, 26 Nov 2026 08:38:41 GMT</pubDate><content:encoded><![CDATA[<p>A common way to handle updates across multiple servers is <strong>Latest Wins</strong>: stamp every change with the current clock time (<code>now()</code>) and keep whichever change has the later timestamp.</p>
<pre><code class="language-sql">UPDATE user_profiles
    SET display_name = :new_name, updated_at = :server_timestamp
    WHERE user_id = :user_id AND updated_at &lt;= :server_timestamp;
</code></pre>
<p>This assumes <strong>every server tells the exact same time</strong> and <strong>the clock always moves smoothly forward</strong>. In real life, every machine has a tiny timing crystal inside that runs slightly fast or slow as temperatures and workloads shift. Background time-sync tools also adjust clocks — sometimes jumping them backward — so a later action can easily get an earlier timestamp.</p>
<hr />
<h2>How It Fails</h2>
<p>Suppose a user updates their profile on Server B when its clock is running fast, and then updates it again on Server A a moment later.</p>
<ol>
<li>Server B's clock is running fast and reads <code>10:00.200</code>. It saves Change 1 with time <code>10:00.200</code>.</li>
<li>A background time check pulls Server B's clock backward by <code>0.300</code> seconds to <code>09:59.900</code>. Server A's clock is at <code>10:00.050</code>.</li>
<li>The user makes a newer change on Server A. It gets stamped <code>10:00.050</code>.</li>
<li>When the servers compare changes, <code>10:00.200</code> looks newer than <code>10:00.050</code>, so the system keeps the old change and drops the newer one.</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/6b02ca197d25590d0534be77/51448d74-3fc0-4acc-a0a2-459fd3568c40.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>Invariant &amp; Mitigation Patterns</h2>
<p><strong>Invariant:</strong> If Change 2 happens <em>because of</em> or <em>after</em> Change 1, no server should treat Change 1 as newer than Change 2.</p>
<ul>
<li><strong>Step Counters (Event Counters):</strong> Instead of trusting clock time, servers pass a simple step number (<code>1</code>, <code>2</code>, <code>3</code>...). When a server receives a message with step <code>3</code>, it sets its own counter to at least <code>4</code> before making a new change. Order comes from what happened first, not from the clock.</li>
<li><strong>Clock + Step Counter Together:</strong> Keep a normal clock timestamp so humans can read dates and times, and attach a backup step number that goes up whenever the clock jumps backward or two changes happen at the same instant.</li>
<li><strong>Single Leader / Ordered Log:</strong> Send changes for the same record through one leader or a single ordered list of events so every change gets a clear sequence number from one source.</li>
</ul>
<hr />
<h2>Trade-Offs</h2>
<p><strong>Step Counters</strong></p>
<ul>
<li><strong>Pros:</strong> Does not care if server clocks are fast, slow, or jumping around.</li>
<li><strong>Cons:</strong> Tells you step order (<code>1</code>, <code>2</code>, <code>3</code>), not real-world clock time like <code>4:15 PM</code>; tracking separate counters per server adds extra data to pass around.</li>
<li><strong>Backfires when:</strong> You need exact wall-clock times for things like expiring sessions, billing windows, or customer support logs.</li>
</ul>
<p><strong>Clock + Step Counter Together</strong></p>
<ul>
<li><strong>Pros:</strong> Still looks like a normal timestamp while preventing backward clock jumps from erasing newer changes.</li>
<li><strong>Cons:</strong> If one server's clock jumps far ahead by mistake, its timestamp can stay artificially high until real time catches up.</li>
<li><strong>Backfires when:</strong> Outside tools or billing systems treat that timestamp as exact real-world time rather than an ordering tag.</li>
</ul>
<p><strong>Single Leader / Ordered Log</strong></p>
<ul>
<li><strong>Pros:</strong> Gives a clean, single order of events that avoids clock mix-ups.</li>
<li><strong>Cons:</strong> Adds extra network wait time and more moving parts to run and recover if a server goes down.</li>
<li><strong>Backfires when:</strong> You send low-stakes, independent updates through one bottleneck when fast local writes matter more.</li>
</ul>
<hr />
<h2>Key Takeaways</h2>
<ol>
<li><strong>Do not trust server clocks (</strong><code>now()</code><strong>) to decide which update came last</strong> across multiple machines.</li>
<li><strong>Latest Wins based on clock time can silently drop real updates</strong> when clocks drift or jump backward.</li>
<li><strong>Separate "what happened first" from "what time does the wall say"</strong> — use step numbers or ordered logs for order, and clocks for human-readable times and expiration rules.</li>
<li><strong>Watch clock sync health in production</strong> — sudden clock jumps often show up as mysterious out-of-order bugs.</li>
<li><strong>Pick the simplest fix that matches your risk</strong>: for low-stakes settings, a small slip may not matter; for money, orders, or user state, tie order to a step counter or ordered log.</li>
</ol>
]]></content:encoded></item><item><title><![CDATA[Network Indistinguishability: Why Timeouts Can Never Tell Slow From Dead]]></title><description><![CDATA[A timeout only shows how long you waited — not if a node crashed, paused, or finished. See why slow vs. dead blurs and how to pick safe timeouts.]]></description><link>https://angeloarcillas.hashnode.dev/network-indistinguishability-why-timeouts-can-never-tell-slow-from-dead</link><guid isPermaLink="true">https://angeloarcillas.hashnode.dev/network-indistinguishability-why-timeouts-can-never-tell-slow-from-dead</guid><category><![CDATA[distributed systems]]></category><category><![CDATA[Reliability]]></category><category><![CDATA[timeout]]></category><category><![CDATA[fault tolerance]]></category><category><![CDATA[architecture]]></category><category><![CDATA[software development]]></category><category><![CDATA[Software Engineering]]></category><category><![CDATA[System Design]]></category><category><![CDATA[backend]]></category><dc:creator><![CDATA[Angelo Arcillas]]></dc:creator><pubDate>Mon, 23 Nov 2026 13:06:37 GMT</pubDate><content:encoded><![CDATA[<p>Engineers routinely treat a request timeout as proof of failure: if Service A waits 500 ms for Service B and gets no reply, Service A marks Service B unhealthy, trips a circuit breaker, or immediately retries against another replica.</p>
<p>The hidden assumption is <strong>synchrony with observable crashes</strong> — that silence equals death, and that network transit and execution times stay bounded within a predictable window. In real networks, <strong>partial failure</strong> is the baseline: packets drop on one direction of a link, garbage collection or container throttling freezes a healthy process for seconds, or a worker commits a database write just as the caller gives up and sends a retry.</p>
<hr />
<h2>How It Fails</h2>
<ol>
<li>A caller sends a request across the network, which delivers it to the target.</li>
<li>The target stalls due to a garbage collection pause or database lock wait, pushing execution past the caller's timeout window.</li>
<li>The caller's timeout expires, so the caller treats the operation as failed or timed out and moves on (or retries).</li>
<li>The target eventually finishes, sends a late response back over the network, and that reply is either dropped or ignored by a caller that has already closed the request context.</li>
</ol>
<img src="https://cdn.hashnode.com/uploads/covers/6b02ca197d25590d0534be77/89e40715-6daa-479b-b47d-87130b0308e0.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>Invariant &amp; Mitigation Patterns</h2>
<p><strong>Invariant:</strong> Never equate a lack of timely response with non-execution or permanent node death; design every caller action around <strong>uncertainty</strong> rather than binary liveness.</p>
<ul>
<li><strong>Bounded Retries with Idempotency:</strong> Pair retries with idempotency keys or conditional writes so a slow or late-arriving first attempt cannot double-apply state when a retry succeeds.</li>
<li><strong>Tail-Aware / Budgeted Timeouts:</strong> Set timeouts from end-to-end latency budgets (such as p99 plus network slack) and propagate remaining deadlines downstream instead of inventing arbitrary local constants.</li>
<li><strong>Asymmetric Partition &amp; Quorum Awareness:</strong> Separate <em>reachability</em> from <em>membership/ownership</em> — use leases, fencing tokens, or quorum checks rather than unilateral health eviction when one side looks silent.</li>
</ul>
<pre><code class="language-python">async def call_with_deadline(client, payload: dict, deadline_s: float, max_attempts: int = 2):
    headers = {"Idempotency-Key": payload["tx_id"]}
    for attempt in range(max_attempts):
        remaining = deadline_s - time.monotonic()
        if remaining &lt;= 0:
            raise TimeoutError("Request budget exhausted")
        wait = min(remaining, 0.25)  # Per-attempt cap so one slow call doesn't eat the whole budget
        headers["X-Deadline-Ms"] = str(max(1, int(wait * 1000)))
        try:
            return await client.post("/charges", json=payload, headers=headers, timeout=wait)
        except TimeoutError:
            if attempt + 1 == max_attempts:
                raise
            await asyncio.sleep(min(max(0.0, remaining), random.uniform(0.01, 0.05))) # Jittered backoff within budget
</code></pre>
<hr />
<h2>Trade-Offs</h2>
<p><strong>Idempotent Retries</strong></p>
<ul>
<li><strong>Pros</strong>: Prevents duplicate side effects when a slow request actually succeeded behind a timeout.</li>
<li><strong>Cons</strong>: Requires durable idempotency storage, deduplication windows, and careful handling of in-flight vs. completed states.</li>
<li><strong>When it backfires</strong>: Unbounded or un-jittered retries during a genuine slowdown amplify load (retry storms) and keep queues saturated.</li>
</ul>
<p><strong>Fail-Fast (Short) Timeouts</strong></p>
<ul>
<li><strong>Pros</strong>: Frees caller threads, sockets, and upstream capacity quickly when a dependency stalls.</li>
<li><strong>Cons</strong>: Prematurely aborts legitimate requests during transient p99/p999 spikes, wasting work already started downstream.</li>
<li><strong>When it backfires</strong>: Setting timeouts below normal tail latency or without deadline propagation causes cascading aborts across multi-hop call chains.</li>
</ul>
<p><strong>Long-Wait Timeouts &amp; Leases</strong></p>
<ul>
<li><strong>Pros</strong>: Reduces false positives during GC pauses, microbursts, and asymmetric packet loss.</li>
<li><strong>Cons</strong>: Delays failover detection and ties up caller resources longer during real outages.</li>
<li><strong>When it backfires</strong>: Overly long leases or waits stall recovery when a node truly dies, while overly short leases under clock drift or CPU starvation cause split-brain churn.</li>
</ul>
<hr />
<h2>Key Takeaways</h2>
<ul>
<li>A timeout is a <strong>resource-protection boundary</strong>, not a truth oracle about remote health.</li>
<li>Assume <strong>asymmetry</strong>: a node can receive traffic without sending replies, or finish work after the caller stops listening.</li>
<li>Always couple retries with <strong>idempotency, jitter, and retry budgets</strong> so recovery does not become a retry storm.</li>
<li>Size timeouts to <strong>observed tail latency and remaining request budgets</strong>, never wishful thinking.</li>
<li>Require <strong>fencing or quorum consensus</strong> before letting a timeout trigger state takeover.</li>
</ul>
]]></content:encoded></item></channel></rss>