<?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 Shariar Islam Tutul on Medium]]></title>
        <description><![CDATA[Stories by Shariar Islam Tutul on Medium]]></description>
        <link>https://medium.com/@tutulewu214?source=rss-1754f8924905------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2YyY2NHZy0-z9V0z2nBDzg.jpeg</url>
            <title>Stories by Shariar Islam Tutul on Medium</title>
            <link>https://medium.com/@tutulewu214?source=rss-1754f8924905------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 16:17:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tutulewu214/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[Why Your App Keeps Crashing: Meet the Bouncer That Saves Distributed Systems]]></title>
            <link>https://medium.com/@tutulewu214/why-your-app-keeps-crashing-meet-the-bouncer-that-saves-distributed-systems-87d5eaf570c8?source=rss-1754f8924905------2</link>
            <guid isPermaLink="false">https://medium.com/p/87d5eaf570c8</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[resilience]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Shariar Islam Tutul]]></dc:creator>
            <pubDate>Thu, 23 Jul 2026 12:41:37 GMT</pubDate>
            <atom:updated>2026-07-23T12:41:37.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ErGqd0Wmeu4N9LE019HjfA.png" /></figure><blockquote>A story-driven guide to Circuit Breaker, Retry, and Fallback — with real Resilience4j code you can paste into your next Spring Boot project</blockquote><p>One unhealthy service should never be allowed to take down an entire system. Yet in modern microservices and IoT architectures, that’s exactly what happens — a single slow dependency triggers a chain reaction that overwhelms everything around it.</p><p>This is why resilience patterns like <strong>Circuit Breaker</strong>, <strong>Retry</strong>, and <strong>Fallback</strong> exist. Let’s learn them through a story, then build them in Java.</p><h3>The Restaurant That Collapsed</h3><p>Imagine you’re at a busy restaurant. The kitchen suddenly becomes overwhelmed, and orders stop coming out. Instead of telling customers what’s happening, every waiter keeps running back into the kitchen every 30 seconds asking, “Is table 12 ready now?” The answer is always no — but they keep asking anyway.</p><p>Soon every waiter is standing outside the kitchen instead of serving customers. The dining area fills with angry guests, new customers keep arriving, and nobody is serving anyone anymore.</p><p>The restaurant didn’t collapse because the kitchen was slow. It collapsed because everyone kept asking the same failing system to do more work.</p><p>You’ve just experienced a <strong>cascading failure</strong> — and it’s exactly what happens inside distributed systems:</p><pre>API Gateway → Order Service → Payment Service (slow) → Database</pre><p>The Payment Service slows down. The Order Service keeps waiting. The API Gateway keeps waiting. Clients retry. Threads pile up, connection pools become exhausted, CPU usage spikes — and eventually everything stops. One sick service infects the entire system.</p><p>Here’s what that looks like in real Spring code, with no protection at all:</p><pre>@Configuration<br>public class RestClientConfig {<br><br>    @Bean<br>    RestClient paymentRestClient(RestClient.Builder builder) {<br>        return builder<br>                .baseUrl(&quot;http://payment-service&quot;)<br>                .build();<br>    }<br>}<br><br>@Service<br>@RequiredArgsConstructor<br>public class OrderService {<br><br>    private final RestClient paymentRestClient;<br><br>    public OrderResponse placeOrder(OrderRequest request) {<br><br>        // If Payment Service becomes slow,<br>        // this thread waits here until the response arrives<br>        // (or until a timeout occurs).<br><br>        PaymentResponse paymentResponse = paymentRestClient.post()<br>                .uri(&quot;/api/payments&quot;)<br>                .body(request)<br>                .retrieve()<br>                .body(PaymentResponse.class);<br><br>        return new OrderResponse(<br>                request.getOrderId(),<br>                paymentResponse.status()<br>        );<br>    }<br>}</pre><p>Nothing here is wrong syntactically. It works in the demo. Then traffic spikes, payment-service slows down, and every thread in the pool is now holding the door open for a kitchen that&#39;s on fire — including requests that have nothing to do with payments. That&#39;s the bug hiding in plain sight: no timeout, no circuit breaker, no fallback.</p><h3>Why This Is Even Worse in IoT</h3><p>Imagine a concert ticket website on launch day. 50,000 people are trying to buy tickets. Suddenly, the payment server becomes slow. Every customer’s app thinks, <em>“Maybe my internet is acting up,”</em> so it automatically taps <strong>“Try Again.”</strong> Now the server isn’t handling the original 50,000 requests anymore — it’s handling the original requests <strong>plus thousands of retries</strong>, all at the same time. The server becomes even slower, causing even more retries. A small problem quickly snowballs into a complete outage.</p><p>Infrastructure overloads, devices waste battery, bandwidth disappears, and the cloud bill spikes. A service that was only slightly unhealthy becomes completely unavailable. This effect has a name: a <strong>retry storm</strong> — the exact mechanism that turns a five-minute blip into a two-hour outage.</p><h3>Meet the Hero: Circuit Breaker</h3><p>If you’ve ever looked inside your home’s electrical panel, you’ve seen a circuit breaker. When too much electricity flows through a wire, it doesn’t keep trying — it cuts the power to protect the house.</p><p>Software borrowed this idea directly. A <strong>Circuit Breaker</strong> watches calls to an external service, and when it notices repeated failures, it says: <em>“Enough. Stop sending requests here until things recover.”</em> Instead of letting your application keep waiting and consuming resources, it fails immediately — a decision that can save an entire production system.</p><h3>The Three States</h3><blockquote><strong>CLOSED — everything is fine.</strong> This is the default state. Every request passes through while the breaker quietly watches.</blockquote><blockquote><strong>OPEN — stop, don’t even ask.</strong> After enough failures, the breaker opens and stops calling the failing service entirely. No waiting, no timeout, no wasted threads — the struggling service gets breathing room. This is called <strong>fail fast</strong>, and it’s the core benefit of the whole pattern.</blockquote><blockquote><strong>HALF_OPEN — let’s carefully test again.</strong> After a cooldown period, the breaker lets a few trial requests through. If they succeed, it closes again; if they fail, it reopens immediately — like dipping a toe in the pool instead of diving in.</blockquote><pre>┌────────────┐   failure/slow-call rate &gt; threshold   ┌────────────┐<br>        │   CLOSED   │ ───────────────────────────────────────▶│    OPEN    │<br>        └────────────┘                                         └────────────┘<br>              ▲                                                       │<br>        trial calls succeed                          wait-duration-in-open-state<br>              │                                                       ▼<br>        ┌────────────┐            trial calls fail             ┌────────────┐<br>        │ HALF_OPEN  │◀───────────────────────────────────────│  (retest)   │<br>        └────────────┘                                         └────────────┘</pre><h3>Java Example and configuration</h3><p>Same code protected by a Circuit Breaker</p><pre>@Service<br>@RequiredArgsConstructor<br>public class OrderService {<br><br>    private final RestClient paymentRestClient;<br><br>    @CircuitBreaker(<br>            name = &quot;payment-service&quot;,<br>            fallbackMethod = &quot;paymentFallback&quot;<br>    )<br>    public OrderResponse placeOrder(OrderRequest request) {<br><br>        PaymentResponse paymentResponse = paymentRestClient.post()<br>                .uri(&quot;/api/payments&quot;)<br>                .body(request)<br>                .retrieve()<br>                .body(PaymentResponse.class);<br><br>        return new OrderResponse(<br>                request.getOrderId(),<br>                paymentResponse.status()<br>        );<br>    }<br><br>    private OrderResponse paymentFallback(<br>            OrderRequest request,<br>            Exception ex) {<br><br>        return new OrderResponse(<br>                request.getOrderId(),<br>                &quot;PAYMENT_SERVICE_UNAVAILABLE&quot;<br>        );<br>    }<br>}<br><br><br><br>Now your application behaves like this<br>Client<br> │<br> ▼<br>Order Service<br> │<br> ▼<br>Circuit Breaker<br> │<br> ├──────── CLOSED ───────► Payment Service<br> │<br> └──────── OPEN ─────────► Fallback</pre><pre>Set it to your pom.xml/yml file : <br><br>&lt;dependency&gt;<br>    &lt;groupId&gt;io.github.resilience4j&lt;/groupId&gt; <br>    &lt;artifactId&gt;resilience4j-spring-boot3&lt;/artifactId&gt;<br>    &lt;version&gt;2.2.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><pre>resilience4j:<br>  circuitbreaker:<br>    instances:<br>      paymentService:<br>        failure-rate-threshold: 50            # % of failed calls that trips the breaker<br>        slow-call-rate-threshold: 80          # % of &quot;slow&quot; calls that also trips it<br>        slow-call-duration-threshold: 2s      # a call counts as &quot;slow&quot; past this<br>        minimum-number-of-calls: 10           # don&#39;t judge until we have enough data<br>        sliding-window-type: COUNT_BASED      # or TIME_BASED<br>        sliding-window-size: 10<br>        wait-duration-in-open-state: 30s<br>        permitted-number-of-calls-in-half-open-state: 3<br>        register-health-indicator: true</pre><h3>How Resilience4j Actually Decides to Open</h3><p>Resilience4j keeps a sliding window of the last N calls (or last N seconds, if TIME_BASED) and won&#39;t evaluate anything until minimum-number-of-calls is reached — avoiding a false trip from one unlucky early failure.</p><p>Once there’s enough data, it calculates two independent rates: the <strong>failure rate</strong> (% of calls that threw an exception) and the <strong>slow-call rate</strong> (% of calls that exceeded, even if they succeeded). If either one crosses its threshold, the circuit opens — because a call that &quot;succeeds&quot; but takes 8 seconds is just as dangerous to your thread pool as one that errors out.</p><pre>10 calls: 6 fast successes, 3 failures, 1 slow success (4s)<br>failure-rate = 30%  (below 50% threshold)<br>slow-call-rate = 10% (below 80% threshold)<br>→ stays CLOSED</pre><pre>10 calls: 4 successes, 6 failures<br>failure-rate = 60%  (above 50% threshold)<br>→ OPENS</pre><h3>Retry: Your Optimistic Friend</h3><p>Retry assumes a failure is temporary — a dropped packet, a brief DNS hiccup, a service restart — and simply tries again:</p><pre>Attempt 1 ❌ → wait → Attempt 2 ❌ → wait → Attempt 3 ✅</pre><pre><br><br>@Service<br>public class UserClient {<br>    private final RestTemplate restTemplate;<br>    public UserClient(RestTemplate restTemplate) {<br>        this.restTemplate = restTemplate;<br>    }<br>    @Retry(name = &quot;userService&quot;, fallbackMethod = &quot;getUserFallback&quot;)<br>    public UserDto getUser(Long id) {<br>        return restTemplate.getForObject(<br>                &quot;http://user-service/api/users/&quot; + id, UserDto.class);<br>    }<br>    public UserDto getUserFallback(Long id, Throwable t) {<br>        return new UserDto(id, &quot;UNKNOWN&quot;);<br>    }<br>}</pre><pre>resilience4j:<br>  retry:<br>    instances:<br>      userService:<br>        max-attempts: 3<br>        wait-duration: 2s<br>        retry-exceptions:<br>          - java.net.SocketTimeoutException<br>          - org.springframework.web.client.ResourceAccessException<br>        ignore-exceptions:<br>          - com.example.exception.BusinessValidationException</pre><p>retry-exceptions vs ignore-exceptions matters: retry infrastructure failures (timeouts, connection resets), not business failures like &quot;user not found.&quot; Retrying a 400 Bad Request three times just gets you the same 400, three times slower.</p><p><strong>Retry is good for:</strong> temporary network blips, connection resets, a service restarting mid-deploy, transient database issues.</p><p><strong>Retry becomes dangerous when the operation isn’t safe to repeat.</strong> Suppose your app transfers money. The bank processes it successfully, but the confirmation response gets lost. Your app thinks it failed and retries — and the money gets transferred again. Nothing actually failed; only the response was lost, and Retry couldn’t tell the difference.</p><h3>Idempotency: The Concept That Saves You</h3><p>An operation is <strong>idempotent</strong> if running it once or ten times produces the same result. GET /users and PUT /profile are usually safe. POST /payments, POST /orders, and sending emails or SMS need real care.</p><p>The fix isn’t avoiding Retry — it’s making the risky operation idempotent with an <strong>Idempotency-Key</strong>:</p><pre>@PostMapping(&quot;/api/payments&quot;)<br>public ResponseEntity&lt;PaymentResponse&gt; createPayment(<br>        @RequestHeader(&quot;Idempotency-Key&quot;) String idempotencyKey,<br>        @RequestBody PaymentRequest request) {<br>Optional&lt;PaymentResponse&gt; existing = paymentRepository<br>            .findByIdempotencyKey(idempotencyKey);<br>    if (existing.isPresent()) {<br>        return ResponseEntity.ok(existing.get()); // same result, no double charge<br>    }<br>    PaymentResponse response = paymentService.process(request);<br>    paymentRepository.save(idempotencyKey, response);<br>    return ResponseEntity.ok(response);<br>}</pre><p>The client generates a unique key once, before the first attempt, and sends the same key on every retry — so the server can recognize a repeat and return the original result instead of charging twice.</p><p>A junior engineer sees a failing payment call and asks, “How do I make this retry?” A senior engineer asks, “If this retries, could it duplicate a real-world side effect — and how do I make it idempotent first?” That question is one of the strongest signals interviewers listen for.</p><h3>Retry + Circuit Breaker Together</h3><p>These patterns complement each other — Retry is the optimistic friend, Circuit Breaker is the experienced bodyguard:</p><pre>Client → Retry → Circuit Breaker → Service</pre><p>Retry believes the problem is temporary and tries a few times. If failures continue, the Circuit Breaker steps in and closes the door — further retries never reach the failing service, and the application fails immediately instead of waiting several seconds.</p><pre>@Service<br>public class PaymentClient {<br>    private final RestTemplate restTemplate;<br>    public PaymentClient(RestTemplate restTemplate) {<br>        this.restTemplate = restTemplate;<br>    }<br>    @CircuitBreaker(name = &quot;paymentService&quot;, fallbackMethod = &quot;fallback&quot;)<br>    @Retry(name = &quot;paymentService&quot;, fallbackMethod = &quot;fallback&quot;)<br>    public PaymentResponse charge(PaymentRequest request) {<br>        return restTemplate.postForObject(<br>                &quot;http://payment-service/api/charge&quot;, request, PaymentResponse.class);<br>    }<br>    public PaymentResponse fallback(PaymentRequest request, Throwable t) {<br>        return PaymentResponse.pendingReview(request.getOrderId());<br>    }<br>}</pre><p>By default, CircuitBreaker wraps Retry — the circuit breaker check happens around the entire retry loop, and every individual retry attempt is recorded against the breaker&#39;s failure rate:</p><pre>Circuit CLOSED:<br>  attempt 1 fails → recorded as 1 failure<br>  attempt 2 fails → recorded as 1 more failure<br>  attempt 3 succeeds → recorded as success</pre><pre>Circuit already OPEN:<br>  Retry never runs — CallNotPermittedException thrown instantly</pre><p>The consequence: with max-attempts: 3, one logical call can contribute up to three data points to the circuit breaker&#39;s window, not one. Tune minimum-number-of-calls and failure-rate-threshold with that in mind, or a burst of retried failures can trip the breaker faster than expected.</p><h3>Fallback: The Safety Net</h3><p>Imagine your favorite restaurant is closed today, but instead of a locked door, there’s a sign: <em>“We’re closed — here’s a coupon for the restaurant next door.”</em> That’s a Fallback: when the primary service is unavailable, you provide something useful instead of an error page.</p><pre>@CircuitBreaker(name = &quot;recommendationService&quot;, fallbackMethod = &quot;fallbackRecommendations&quot;)<br>public List&lt;Product&gt; getRecommendations(Long userId) {<br>    return recommendationClient.getPersonalized(userId);<br>}<br>public List&lt;Product&gt; fallbackRecommendations(Long userId, Throwable t) {<br>    return popularProductsService.getTopSellers();<br>}</pre><p>A more production-grade version falls back to the <strong>last known good response</strong> instead of a generic default:</p><pre>@CircuitBreaker(name = &quot;weatherApi&quot;, fallbackMethod = &quot;getCachedWeather&quot;)<br>public WeatherResponse getWeather(String city) {<br>    WeatherResponse response = weatherClient.fetch(city);<br>    cache.put(city, response);<br>    return response;<br>}<br>public WeatherResponse getCachedWeather(String city, Throwable t) {<br>    WeatherResponse cached = cache.getIfPresent(city);<br>    return cached != null ? cached.markAsStale() : WeatherResponse.unavailable(city);<br>}</pre><p>Users often don’t even notice something failed — this is <strong>graceful degradation</strong>: the experience is reduced, not broken.</p><h3>The Rest of the Toolkit</h3><p><strong>Rate Limiter</strong> — the nightclub bouncer, limiting how many requests can enter your system per period:</p><pre>@RateLimiter(name = &quot;searchApi&quot;, fallbackMethod = &quot;rateLimitFallback&quot;)<br>public List&lt;SearchResult&gt; search(String query) {<br>    return searchClient.query(query);<br>}</pre><pre>resilience4j:<br>  ratelimiter:<br>    instances:<br>      searchApi:<br>        limit-for-period: 100<br>        limit-refresh-period: 1m</pre><p><strong>Bulkhead</strong> — named after a ship’s watertight compartments; isolates resources so one slow dependency can’t consume every thread:</p><pre>@Bulkhead(name = &quot;imageProcessing&quot;, type = Bulkhead.Type.THREADPOOL)<br>public CompletableFuture&lt;byte[]&gt; processImage(byte[] input) {<br>    return CompletableFuture.supplyAsync(() -&gt; resizeAndCompress(input));<br>}</pre><pre>resilience4j:<br>  thread-pool-bulkhead:<br>    instances:<br>      imageProcessing:<br>        max-thread-pool-size: 10<br>        core-thread-pool-size: 5<br>        queue-capacity: 20</pre><p><strong>Time Limiter</strong> — refuses to wait forever:</p><pre>@TimeLimiter(name = &quot;reportService&quot;, fallbackMethod = &quot;reportFallback&quot;)<br>public CompletableFuture&lt;Report&gt; generateReport(Long id) {<br>    return CompletableFuture.supplyAsync(() -&gt; reportClient.build(id));<br>}</pre><pre>resilience4j:<br>  timelimiter:<br>    instances:<br>      reportService:<br>        timeout-duration: 5s</pre><p>Put together, a healthy request flow looks like:</p><pre>Client → Rate Limiter → Retry → Circuit Breaker → Time Limiter → Service → Fallback (on failure)</pre><p>Pattern Purpose Retry Recover from temporary failures Circuit Breaker Stop cascading failures Time Limiter Avoid waiting forever Rate Limiter Protect your own system Bulkhead Isolate failures Fallback Keep users happy when services fail</p><h3>Production Best Practices</h3><ul><li>Always set explicit timeouts on your HTTP client — otherwise Resilience4j’s slow-call detection is your only safety net, and it only kicks in after the call already returned.</li><li>Log every state transition (via an EventPublisher listener) so an open circuit triggers an alert instead of a silent outage.</li><li>Give unrelated dependencies separate instance names and thresholds — paymentService and emailService fail and recover differently.</li><li>Use TIME_BASED sliding windows for low-traffic endpoints that may never hit a count-based minimum.</li><li>Expose breaker health via Spring Boot Actuator (register-health-indicator: true) for dashboards and alerts.</li><li>Mark fallback data as stale or degraded rather than presenting it as fresh.</li></ul><h3>Common Mistakes</h3><ol><li>Adding @Retry to non-idempotent operations without an idempotency key.</li><li>Retrying business errors (404, 400) instead of only infrastructure errors.</li><li>Setting failure-rate-threshold without a sane minimum-number-of-calls.</li><li>Forgetting that each retry attempt counts toward the circuit breaker’s window.</li><li>Adding a @CircuitBreaker with no fallback — the user still sees an error, just faster.</li><li>Using one timeout config for both background jobs and user-facing calls.</li><li>Never actually testing the OPEN state in staging.</li></ol><h3>Final Takeaways</h3><p>Production systems rarely fail because of a single bug — they fail because one unhealthy dependency is allowed to drag everything else down with it. Circuit Breakers fail fast to stop that chain reaction. Retries recover from genuinely temporary problems, but only when the operation is safe to repeat. Idempotency keys make risky operations safe to retry in the first place. Fallbacks turn a hard failure into an honest degradation instead of a broken experience.</p><p>The annotations are easy to memorize. The real skill is asking better questions: <em>Could this retry duplicate a real action? How many failures should convince us to stop trying? What should the user see instead of an error?</em> Those questions are what separate code that merely works from software that’s ready for production.</p><h3>🔗 Try It Yourself</h3><p>Every example in this post — the Circuit Breaker, Retry, Idempotency Key, Fallback, Rate Limiter, and Bulkhead configs — lives in a working Spring Boot project here:<br><a href="https://github.com/Tutul191020/resilience4j-demo"> <strong>https://github.com/Tutul191020/resilience4j-demo</strong></a>.<br> Clone it, kill a downstream service on purpose, and watch the breaker trip in real time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87d5eaf570c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connection Pooling Is Not a Feature — It’s a Necessity]]></title>
            <link>https://medium.com/@tutulewu214/connection-pooling-is-not-a-feature-its-a-necessity-30a875bad924?source=rss-1754f8924905------2</link>
            <guid isPermaLink="false">https://medium.com/p/30a875bad924</guid>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[performance-engineering]]></category>
            <dc:creator><![CDATA[Shariar Islam Tutul]]></dc:creator>
            <pubDate>Wed, 20 May 2026 06:48:45 GMT</pubDate>
            <atom:updated>2026-05-20T10:13:02.598Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>What your application pays before the first query even runs</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UbKxIOqApln86tN-" /></figure><h3>The Hook — Ready to Use</h3><p><strong>Before Your Database Does Anything, It’s Already Exhausted</strong></p><p>Picture this.</p><p>A user clicks a button on your application. A request fires. Your backend wakes up and reaches for the database.</p><p>And before a single row is read, before a single index is touched, before your carefully tuned SQL even breathes — your system has already made <strong>7 to 10 round trips across the network.</strong></p><p>Most engineers have no idea this is happening.</p><p>They see slow queries and blame the SQL. They see high latency and blame the network. They see timeouts and immediately think: <em>“We need more connections.”</em></p><p>But the problem was never the query. The problem was the <strong>handshake</strong> — the invisible, multi-stage ritual your database demands before it will talk to you at all.</p><p>Every single connection your application opens goes through this ritual. Authentication. Negotiation. Initialization. Validation. Each step costs time. Each step costs memory. And if your pool is misconfigured, your application is paying this price thousands of times a day — silently, invisibly, in the milliseconds before your code even runs.</p><p>This is called the <strong>Handshake Tax.</strong></p><p>Until you understand it, you cannot:</p><ul><li>Size a connection pool correctly</li><li>Diagnose latency accurately</li><li>Build a production-grade database system</li></ul><p>So before talking about formulas or pool sizing, first understand what actually happens when your application opens a database connection.</p><h3>Why Opening a Connection Is Expensive</h3><p>Many developers imagine a database connection as:</p><blockquote><em>“Just an open socket.”</em></blockquote><p>That assumption is disastrously wrong.</p><p>Opening a database connection is a <strong>multi-stage network and security process</strong> involving:</p><ul><li>TCP setup</li><li>Protocol negotiation</li><li>Authentication</li><li>Session configuration</li><li>Validation checks</li><li>Encryption handshakes</li></ul><p>If you do not use pooling — or your pool constantly churns connections — your application repeatedly pays this cost.</p><p>So before talking about formulas or pool sizing, first understand what actually happens when your application opens a database connection.The 5-Stage Connection Lifecycle:</p><p>1TCP Handshake:</p><p>The operating system first establishes a TCP connection between the application server and the database server.<br>This requires a three-way handshake:</p><pre>Client -&gt; SYN<br>Server -&gt; SYN-ACK<br>Client -&gt; ACK</pre><p><em>Even before authentication begins, at least one network round trip has already occurred.</em></p><p>2 Protocol Negotiation:</p><p>The JDBC driver and database exchange:</p><ul><li>protocol versions</li><li>supported capabilities</li><li>session features</li></ul><p>Examples:</p><ul><li>PostgreSQL startup negotiation</li><li>Oracle TNS packets</li><li>MySQL capability exchange</li></ul><h3>Cost</h3><p>StepRound TripsProtocol negotiation -&gt; 1 RT</p><p>3 Authentication Challenge</p><p>A multi-step dance where the client sends the username, the database sends back an encrypted challenge, and the client responds with verified credentials. (Cost: 2+ Round Trips).</p><pre>Client -&gt; Username<br>Server -&gt; Authentication Challenge<br>Client -&gt; Credential Verification<br>Server -&gt; Authentication Success</pre><p>StepRound TripsAuthentication -&gt; 2+ RTs</p><p>4 Session Initialization</p><p>After authentication, the session must be configured.Applications frequently execute commands such as:</p><pre>ALTER SESSION SET TIME_ZONE = &#39;UTC&#39;;<br><br>ALTER SESSION SET NLS_DATE_FORMAT = &#39;YYYY-MM-DD&#39;;</pre><p>ALTER SESSION SET NLS_DATE_FORMAT = ‘YYYY-MM-DD’;<br>These settings ensure that timestamps, dates, languages, and regional formats remain consistent between the application and the database.<br>Without proper initialization, subtle production bugs can emerge due to timezone or locale mismatches.</p><p>5 Pool Validation</p><p>Before a connection enters the pool, the pool validates it.</p><p>Typical validation queries:</p><pre>SELECT 1;</pre><p>Oracle</p><pre>SELECT 1 FROM DUAL;</pre><h3>Cost</h3><p>StepRound TripsValidation -&gt; 1 RT</p><h4>🔒 The Encryption Penalty</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qLGmAJcDqIQSxvZA" /></figure><p>Modern systems almost always use SSL/TLS.</p><p>That means additional:</p><ul><li>key exchanges</li><li>certificate negotiation</li><li>cryptographic setup</li></ul><p>before communication becomes secure.</p><h3>Result</h3><p>More network round trips.</p><p>More latency.</p><p>More CPU usage.</p><p>Security is absolutely worth it.</p><p>But it increases the cost of creating connections even further.</p><h3>Total Cost of Opening a Single Connection</h3><ul><li>TCP Handshake → 1 RT</li><li>Protocol Negotiation → 1 RT</li><li>Authentication → 2–4 RTs</li><li>Session Initialization → 1–2 RTs</li><li>Pool Validation → 1 RT</li><li>TLS / SSL Negotiation → 1–2 RTs</li></ul><blockquote><em>Total Cost: 7–10 Round Trips</em></blockquote><h4>The Real Cost in Numbers</h4><blockquote>Let’s stop talking abstractly.</blockquote><p>At 100 requests/minute 🔌 100 fresh connections opened 🔄 700–1,000 network round trips ⏱ Up to 20 seconds of pure overhead</p><p>At 1,000 requests/minute 🔌 1,000 fresh connections opened 🔄 7,000–10,000 network round trips ⏱ 35–200 seconds of pure overhead</p><p>At 10,000 requests/minute 🔌 10,000 fresh connections opened 🔄 70,000–100,000 network round trips ⏱ ~33 minutes of overhead — every single minute</p><p>That last number deserves a full stop.</p><p>At 10,000 requests per minute without pooling, your system spends more time negotiating connections than executing queries. You haven’t built a database layer — you’ve built a handshake factory.</p><h3>Why Latency Matters</h3><p>The handshake tax scales brutally with network latency.</p><h3>Connection Establishment Cost in Deployment Environment</h3><blockquote>Same Data Center — RTT: 0.5–2 ms | Total Connection Cost: 5–20 ms</blockquote><blockquote>Cross Data Center — RTT: 5–20 ms | Total Connection Cost: 50–200 ms</blockquote><blockquote>Cross Region — RTT: 80–150 ms | Total Connection Cost: 800–1,500 ms</blockquote><p>Then follow it with a bold punchline sentence:</p><blockquote>Cross-region deployments can spend over 1 second just to open a connection — before a single byte of your application data is sent.</blockquote><h3>The Hidden Memory Tax</h3><p>Latency is only half the problem.</p><p>Every open connection consumes database resources.</p><p>Each connection may allocate:</p><ul><li>session state</li><li>transaction context</li><li>cursor structures</li><li>authentication metadata</li><li>internal process memory</li></ul><h3>Estimated Memory Usage</h3><p>Pool Size &amp; Approx RAM Usage</p><p>20 connections~400 MB</p><p>100 connections 1–3 GB</p><p>600 connections Up to 18 GB</p><p>That memory is stolen from:</p><ul><li>buffer cache</li><li>index caching</li><li>query execution</li><li>sorting</li><li>joins</li></ul><p>Your database becomes slower simply because too many idle sessions exist.</p><h4>The Irony of Massive Pools</h4><p>Connection pools were invented to eliminate handshake overhead.</p><p>But many teams create a second disaster:</p><blockquote><em>Hundreds of permanently open sessions.</em></blockquote><p>They eliminate connection latency…</p><p>…while creating:</p><ul><li>CPU context switching</li><li>lock contention</li><li>scheduler overhead</li><li>database thrashing</li></ul><blockquote>The database stops executing queries efficiently because it is busy managing sessions.</blockquote><h3>So Why Pool At All?</h3><p>Connection pools exist to solve exactly one problem: never pay the handshake tax twice.</p><p>Instead of opening a fresh connection per request, a pool pre-warms a set of connections at startup. Your application borrows one, uses it, and returns it. The 7–10 round trip ritual happens once — not thousands of times per minute.</p><p><em>Think of it like a taxi rank versus hailing a car from scratch every time.</em></p><blockquote>Without pooling → every passenger waits for a car to be manufactured, registered, and driven over before their ride begins.</blockquote><blockquote>With pooling → cars are already waiting. You get in and go.</blockquote><p>The pool is not optional in production. It is the difference between a system that handles load and one that collapses under it.</p><h3>The Trap You Haven’t Seen Yet</h3><p>Pooling gets rid of the handshake tax. Now you know that.</p><p>But addressing one issue without considering another is not engineering — it’s simply shifting the fire to another part of the building.</p><p><em>This is what no one tells you when they give you a connection pool:</em></p><blockquote>The size of that pool is a gun.</blockquote><p>If you aim incorrectly, your system will not only become slower — it will fail in ways that have absolutely nothing to do with the pool. Cascading timeouts, thread starvation, database CPU usage at 100% even though your SQL code is perfectly optimized and just waiting for its turn.</p><p>Too few connections and your application starts to behave like a highway during rush hour — all threads queued, all users queued, all requests stacked one after another.</p><p>Too many connections and your database runs out of steam. Not because of lack of connections but because of too many. Your CPU won’t execute any queries anymore but instead spend its power managing the mess of hundreds of concurrent sessions competing for the same hardware resources.</p><p><em>Both situations look like a problem with the database. Both are actually a problem with the pool configuration.</em></p><p>The right number of connections is not an estimate. It is not a default. It is not something that worked at your previous job.</p><p>It is a calculation based on two queueing theory rules, one piece of hardware knowledge and proven in practice by a banking system that pounded its database with 640 connections despite its infrastructure being designed for 216.</p><p>When they changed the pool size, it did not merely improve performance.</p><p>It revolutionized it.</p><blockquote>All the math behind this story is in Chapter -2 ….. Don’t skip it</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30a875bad924" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Boot: Why This Revolutionary Framework is a Must-Know for Java Developers]]></title>
            <link>https://medium.com/@tutulewu214/spring-boot-why-this-revolutionary-framework-is-a-must-know-for-java-developers-1ca05dd2e852?source=rss-1754f8924905------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ca05dd2e852</guid>
            <dc:creator><![CDATA[Shariar Islam Tutul]]></dc:creator>
            <pubDate>Sun, 10 Nov 2024 10:56:52 GMT</pubDate>
            <atom:updated>2024-11-10T10:56:52.854Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*xVzVgy54M0Ci_fkLS1LyeQ.png" /></figure><p>This will be a basic guide/overview of Spring Boot. This article explores the unique aspects of Spring Boot that make it a standout choice for Java developers, particularly those interested in creating enterprise-level and microservice-based applications.</p><h3>Why SpringBoot:</h3><p>As Java developers continue to seek tools that simplify complex tasks, Spring Boot has emerged as a leading framework that empowers developers to create production-ready applications with remarkable ease. One of the most appealing aspects of Spring Boot is its simplicity. Unlike traditional Java frameworks that require extensive XML configurations, Spring Boot provides a streamlined setup process with minimal configuration</p><blockquote>Spring Boot supports embedded servers, including Tomcat, Jetty, and Undertow, which allow applications to run independently without requiring external servers. This embedded server functionality is a game-changer, enabling developers to package their entire application into a single JAR or WAR file, which can be deployed anywhere</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ca05dd2e852" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reflection of CS50-Harvard’s Introduction to Computer Science]]></title>
            <link>https://medium.com/@tutulewu214/reflection-of-cs50-harvards-introduction-to-computer-science-638277acebec?source=rss-1754f8924905------2</link>
            <guid isPermaLink="false">https://medium.com/p/638277acebec</guid>
            <category><![CDATA[harvard-cs50]]></category>
            <dc:creator><![CDATA[Shariar Islam Tutul]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 12:58:21 GMT</pubDate>
            <atom:updated>2024-11-06T09:38:16.113Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuShLONJ8qWXTut42q4WUw.jpeg" /></figure><h3>preface</h3><p>For the past four weeks, I have been taking an online course named CS50, which is instructed by David J. Malan, a professor of computer science at Harvard University. This course provides essential knowledge for anyone interested in learning the fundamentals of computer science. The syllabus is divided into 10 distinct video segments, each designed to highlight key concepts for the week. These videos help identify the core topics to concentrate on and offer repeated exposure to reinforce the material.</p><h3>why choose cs50?</h3><p>It encompasses a broad array of subjects, including the basics of computer science, algorithms, data structures, and programming languages like C, Python, and SQL. This ensures you receive a comprehensive introduction to the field.</p><blockquote>It’s free! You’ll have access to the lectures and course materials.</blockquote><p>In each lecture, the professor will alternate between presentation slides and his development environment, coding live to illustrate the concepts being discussed. This approach includes demonstrating live errors, which helps highlight that even experienced programmers can make simple mistakes and shows how to debug effectively.</p><h3>Very beginning of the course</h3><p>In Week 0, we will explore Scratch, a graphical programming language developed by MIT. With Scratch, you don’t need to write traditional code, allowing you to see how enjoyable programming can be. In Week 1, we’ll shift focus to the basics of C programming and translate the concepts learned in Scratch into actual C code. In C programming, we can explore fundamental concepts such as functions, header files, libraries, data types, conditional statements, variables, loops, pseudocode, operators, integer overflow, and floating-point errors, among others.</p><blockquote>At the very beginning of the course, we start with the foundational concepts that lay the groundwork for everything that follows. This includes an introduction to basic programming principles, setting up your development environment, and familiarizing yourself with the tools and languages you’ll be using. It’s all about building a solid base to ensure you’re prepared for the more complex topics that come later.</blockquote><h3>Week (2–3)</h3><p>In week 2, the focus is on arrays . We cover topics such as how your program compiles, debugging techniques, arrays, characters, strings, and command-line arguments. Additionally, we explore preprocessing, compiling, assembling, linking, debugging, cryptography, and more.</p><blockquote>Week 3 is particularly engaging as it revisits familiar algorithm concepts, like searching and sorting, but with a fresh perspective. The instructor visually compares the time differences between Bubble Sort, Selection Sort, and Merge Sort, making it easier to understand their efficiencies.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*Z5GPN_R7EkaTqHul5dmEfw.png" /></figure><h3>Week (4–5)</h3><p>In week four delves into memory management, covering topics like pointers, memory addresses, allocation and freeing of memory, detecting memory leaks, and understanding how a stack overflow occurs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*DGJ7oXvSUxOsAKt4DlYIxg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*j5jn7OzJ31yvcblktvQfzQ.png" /></figure><blockquote>However, by the end of each lesson and project, you’ll clearly see that the learning objectives have been achieved. Ultimately, what matters most is reinforcing your understanding and moving forward with greater confidence.</blockquote><p>In week six, the course shifts from C to Python, a widely-used programming language known for its ease of learning and use compared to C. You’ll tackle problem sets that involve converting your previous C programs into Python.</p><p>In week seven, you’ll dive into relational databases and SQL (Structured Query Language), using SQLite to run queries both on the command line and within Python.</p><p>Week eight introduces the fundamentals of the internet and the web, focusing on client-side technologies like HTML, CSS, and JavaScript.</p><p>In week nine, you’ll delve into Flask, a Python framework for building web applications. You’ll explore topics such as forms, layouts, templating with Jinja, handling POST and GET requests, and sending emails from a Flask application. Additionally, you’ll go through the process of building a full-stack application.</p><h3>Benefits of CS50</h3><p><strong>Engaging Content:</strong> The course is known for its engaging lectures, interactive problem sets, and hands-on projects, which make learning both challenging and enjoyable.</p><p><strong>Real-World Applications:</strong> CS50 emphasizes real-world problem-solving skills, allowing students to apply what they’ve learned to practical scenarios.</p><p><strong>Strong Foundation:</strong> Completing CS50 provides a solid foundation in computer science, preparing students for further studies or careers in technology.</p><h3>Drawbacks of CS50</h3><p><strong>Not Beginner-Friendly:</strong> Despite being an introductory course, CS50 moves quickly and assumes a certain level of comfort with abstract concepts, which may not be ideal in my opinion ,for complete beginners.</p><h3>My point of view</h3><blockquote>If someone has significant prior experience in computer science, this course might not be the best fit to fulfill their expectations , as it covers fundamental concepts that they may already be familiar with. On the other hand, for someone who is completely new to the field and unfamiliar with the terms and topics covered, the course can provide a broad overview, but may leave them with a basic understanding of many topics rather than deep expertise in any one area — essentially becoming a jack of all trades, master of none.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=638277acebec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>