<?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 Emre Dursun on Medium]]></title>
        <description><![CDATA[Stories by Emre Dursun on Medium]]></description>
        <link>https://medium.com/@emre.dursun0022?source=rss-89c2acfa4865------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0-1N3F8HDWj638KYPfNcpQ.png</url>
            <title>Stories by Emre Dursun on Medium</title>
            <link>https://medium.com/@emre.dursun0022?source=rss-89c2acfa4865------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 02:17:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@emre.dursun0022/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[The WebSocket Scaling Problem Nobody Mentions Until Production]]></title>
            <link>https://medium.com/@emre.dursun0022/the-websocket-scaling-problem-nobody-mentions-until-production-2750c10cc350?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/2750c10cc350</guid>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Wed, 15 Apr 2026 11:19:49 GMT</pubDate>
            <atom:updated>2026-04-15T11:19:49.220Z</atom:updated>
            <content:encoded><![CDATA[<p>Implementing WebSocket for real-time features is exciting. Scaling it in a multi-instance Kubernetes environment is where the excitement ends and the engineering begins.</p><p>When we built live operational dashboards for ground handling teams using WebSocket, everything worked perfectly in development. One server instance, one WebSocket connection, instant updates. Then we deployed to OpenShift with 3 replicas behind a load balancer — and half the users stopped receiving updates.</p><p>The reason is fundamental: WebSocket is a stateful, persistent connection. When User A connects, their WebSocket session lives on Pod 1. When the backend publishes an event on Pod 2 (because a different API request was routed there), Pod 2 broadcasts it to its local WebSocket sessions — which does not include User A.</p><p>Spring’s SimpMessagingTemplate sends messages to sessions on the current JVM only. It has no built-in cross-instance broadcasting.</p><p>The solution is an external message broker as a relay. We already had RabbitMQ in our stack, so we used Spring’s STOMP broker relay:</p><pre>@Override<br>public void configureMessageBroker(MessageBrokerRegistry registry) {<br>    registry.enableStompBrokerRelay(&quot;/topic&quot;, &quot;/queue&quot;)<br>            .setRelayHost(&quot;rabbitmq-cluster&quot;)<br>            .setRelayPort(61613)   // STOMP port, not AMQP<br>            .setSystemHeartbeatSendInterval(10000)<br>            .setSystemHeartbeatReceiveInterval(10000);<br>}</pre><p>Now when any pod publishes to /topic/flight-updates, RabbitMQ relays it to all pods, and every connected WebSocket client receives the message regardless of which pod they are connected to.</p><p>But there is a subtlety that cost us a full day of debugging: the heartbeat configuration. Without explicit heartbeat settings, the STOMP relay connection between your pods and RabbitMQ can silently go stale behind a network load balancer that drops idle TCP connections. We set 10-second heartbeats to keep the relay alive.</p><p>Also worth noting — if a pod restarts, all WebSocket sessions on that pod are dropped. Clients need reconnection logic with exponential backoff. The server does not remember them:</p><pre>function connect() {<br>    const socket = new SockJS(&#39;/ws&#39;);<br>    stompClient = Stomp.over(socket);<br>    stompClient.connect({}, onConnected, () =&gt; {<br>        setTimeout(connect, Math.min(retryDelay *= 2, 30000));<br>    });<br>}</pre><p>WebSocket is simple in concept but has real operational cost in distributed environments. Design for the multi-pod reality from day one, not as an afterthought.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2750c10cc350" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Profiles Are Not a Configuration Strategy]]></title>
            <link>https://medium.com/@emre.dursun0022/spring-profiles-are-not-a-configuration-strategy-f7f170dd3c33?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7f170dd3c33</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Wed, 15 Apr 2026 11:19:37 GMT</pubDate>
            <atom:updated>2026-04-15T11:19:37.619Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a take that might be controversial, but after managing Spring Boot services across multiple deployment environments, I am convinced: relying heavily on Spring Profiles (application-dev.yml, application-prod.yml, application-staging.yml) is a pattern that does not scale.</p><p>Here is why. In our aviation platform, we started with the classic setup — application-dev.yml for local development, application-prod.yml for production. Then we needed a staging profile. Then a UAT profile. Then per-client profiles because different airports had different database configurations. Within a year, we had 11 profile-specific YAML files, and nobody could confidently answer the question: &quot;What configuration is actually running in production for Airport X?&quot;</p><p>The deeper problem is that Spring Profiles conflate two different concerns: environment-specific values (database URLs, credentials, broker addresses) and application behavior flags (feature toggles, batch sizes, cache TTLs). These change at different rates and for different reasons.</p><p>What worked for us was externalizing environment-specific values entirely and keeping profiles minimal:</p><pre># application.yml — the ONLY config file in the codebase<br>spring:<br>  datasource:<br>    url: ${DB_URL}<br>    username: ${DB_USERNAME}<br>    password: ${DB_PASSWORD}<br>  rabbitmq:<br>    host: ${RABBITMQ_HOST}<br>app:<br>  cache:<br>    flight-ttl: ${FLIGHT_CACHE_TTL:300}<br>  batch-size: ${BATCH_SIZE:50}</pre><p>In OpenShift, these environment variables come from ConfigMaps and Secrets:</p><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  name: flight-service-config<br>data:<br>  DB_URL: &quot;jdbc:postgresql://db-prod:5432/flights&quot;<br>  RABBITMQ_HOST: &quot;rabbit-cluster.prod&quot;<br>  FLIGHT_CACHE_TTL: &quot;600&quot;</pre><p>Now every environment uses the same application code with the same YAML structure. The only difference is the external configuration injected at deployment time. No more guessing which profile overrides what. No more “it works on staging” surprises.</p><p>The one profile I kept: local, strictly for development conveniences like enabling H2 console or disabling security. It never goes near production.</p><p>Configuration management sounds boring until it causes a production incident. Keep it simple, keep it external, keep it auditable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7f170dd3c33" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why EntityGraph Is the N+1 Killer You Are Probably Not Using]]></title>
            <link>https://medium.com/@emre.dursun0022/why-entitygraph-is-the-n-1-killer-you-are-probably-not-using-a784eb3dcfd6?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/a784eb3dcfd6</guid>
            <category><![CDATA[spring-data-jpa]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 09:24:06 GMT</pubDate>
            <atom:updated>2026-04-08T09:24:06.444Z</atom:updated>
            <content:encoded><![CDATA[<p>Every Java developer knows the N+1 query problem. You fetch 100 flights, and Hibernate fires 100 additional queries to load each flight’s passenger list. The textbook answer is JOIN FETCH in JPQL. But after years of dealing with this in production, I think @EntityGraph is the better tool — and almost nobody uses it properly.</p><p>Here is why JOIN FETCH becomes a trap in real applications. Suppose you have a Flight entity with three lazy associations: passengers, crewMembers, and baggageRecords. Different service methods need different combinations:</p><pre>// Service A needs passengers<br>&quot;SELECT f FROM Flight f JOIN FETCH f.passengers WHERE f.id = :id&quot;<br><br>// Service B needs passengers + crew<br>&quot;SELECT f FROM Flight f JOIN FETCH f.passengers JOIN FETCH f.crewMembers WHERE f.id = :id&quot;<br><br>// Service C needs all three<br>&quot;SELECT f FROM Flight f JOIN FETCH f.passengers JOIN FETCH f.crewMembers JOIN FETCH f.baggageRecords WHERE f.id = :id&quot;</pre><p>You end up with three nearly identical queries in your repository. Worse, Hibernate throws a MultipleBagFetchException if two of those associations are List types — you cannot JOIN FETCH two bags in a single query.</p><p>@EntityGraph solves both problems:</p><pre>public interface FlightRepository extends JpaRepository&lt;Flight, Long&gt; {<br>    <br>    @EntityGraph(attributePaths = {&quot;passengers&quot;})<br>    Optional&lt;Flight&gt; findWithPassengersById(Long id);<br><br>    @EntityGraph(attributePaths = {&quot;passengers&quot;, &quot;crewMembers&quot;})<br>    Optional&lt;Flight&gt; findWithPassengersAndCrewById(Long id);<br><br>    @EntityGraph(attributePaths = {&quot;passengers&quot;, &quot;crewMembers&quot;, &quot;baggageRecords&quot;})<br>    Optional&lt;Flight&gt; findFullDetailById(Long id);<br>}</pre><p>No JPQL at all. Spring Data derives the query from the method name, and the @EntityGraph tells Hibernate which associations to load eagerly for that specific call. Each method reuses the same base query logic but fetches different association depths.</p><p>The critical detail: @EntityGraph uses LEFT JOIN by default (type = LOAD), so it will not filter out entities that have empty associations — unlike JOIN FETCH which uses INNER JOIN unless you explicitly write LEFT JOIN FETCH.</p><p>One more thing. For the MultipleBagFetchException issue, @EntityGraph does not magically bypass it. If two associations are List, change one to Set. This is a Hibernate limitation, not a JPA one, and it applies regardless of your fetch strategy.</p><p>Pick the right tool for the right join. Your repository will thank you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a784eb3dcfd6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Spring Boot Startup Secret That Saved Us 40 Seconds]]></title>
            <link>https://medium.com/@emre.dursun0022/the-spring-boot-startup-secret-that-saved-us-40-seconds-231d1b2725f8?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/231d1b2725f8</guid>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[openshift]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Wed, 08 Apr 2026 09:16:11 GMT</pubDate>
            <atom:updated>2026-04-08T09:16:11.307Z</atom:updated>
            <content:encoded><![CDATA[<p>When your Spring Boot application takes over a minute to start on OpenShift, every second matters — especially when pods are scaling under load and health checks are ticking.</p><p>We had a microservice that took 62 seconds to become ready. The usual suspects — component scanning, database connection pools, Hibernate DDL validation — all checked out fine. The real killer was something I did not expect: RabbitMQ lazy connection initialization combined with Keycloak’s JWKS endpoint resolution at startup.</p><p>Here is what was happening. Spring AMQP, by default, establishes the RabbitMQ connection lazily — on the first message publish or consume. Sounds efficient, right? But in an OpenShift environment with readiness probes, this meant the application reported “ready” before it could actually process messages. Then when the first request arrived, it spent 8 seconds negotiating the AMQP connection, TLS handshake, and channel creation — under user traffic.</p><p>The fix was to force eager connection initialization:</p><pre>@Bean<br>public ApplicationRunner rabbitWarmup(CachingConnectionFactory factory) {<br>    return args -&gt; {<br>        factory.createConnection().close();<br>        log.info(&quot;RabbitMQ connection warmed up&quot;);<br>    };<br>}</pre><p>But that was only half the story. Our OAuth2 resource server was configured to fetch Keycloak’s JWKS (JSON Web Key Set) on the first incoming request. In a containerized environment where Keycloak was behind an internal service mesh, DNS resolution plus the HTTPS call added another 12 seconds on first request.</p><p>The solution:</p><pre>@Bean<br>public ApplicationRunner jwksWarmup(JwtDecoder jwtDecoder) {<br>    return args -&gt; {<br>        try {<br>            // Force JWKS fetch during startup, not on first request<br>            ((NimbusJwtDecoder) jwtDecoder).decode(&quot;dummy&quot;);<br>        } catch (Exception ignored) {<br>            // Expected to fail, but JWKS keys are now cached<br>        }<br>        log.info(&quot;JWKS keys pre-fetched&quot;);<br>    };<br>}</pre><p>Yes, we intentionally decode a garbage token just to trigger the key fetch. It fails — but the JWK set is now cached. First real request goes from 12 seconds to 15 milliseconds.</p><p>The broader principle: in containerized deployments, “lazy” is not always smart. Move your pain to startup time, where it is predictable, instead of letting it surprise your first users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=231d1b2725f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Your Spring Boot OAuth2 Resource Server Rejects Valid Tokens]]></title>
            <link>https://medium.com/@emre.dursun0022/why-your-spring-boot-oauth2-resource-server-rejects-valid-tokens-03ea61f6fcc7?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/03ea61f6fcc7</guid>
            <category><![CDATA[spring-security]]></category>
            <category><![CDATA[jwt]]></category>
            <category><![CDATA[oauth2]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[keycloak]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Wed, 11 Mar 2026 12:31:27 GMT</pubDate>
            <atom:updated>2026-03-11T12:31:27.297Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have ever stared at a 401 Unauthorized response from a Spring Boot resource server while holding a perfectly valid JWT — this one is for you.</p><p>One of the most common and confusing issues with Spring Security OAuth2 Resource Server is the iss (issuer) claim mismatch. Your token says the issuer is https://keycloak.internal:8443/realms/myapp but your resource server is configured with https://keycloak.company.com/realms/myapp. Both point to the same Keycloak instance, but Spring&#39;s JwtIssuerValidator does a strict string comparison. Different URL = rejected token.</p><p>This is especially common in environments where the token is issued behind an internal network address but validated from a service that sees the public DNS.</p><p>The fix is not to disable issuer validation (please do not do that). Instead, provide a custom validator:</p><pre>@Bean<br>public JwtDecoder jwtDecoder() {<br>    NimbusJwtDecoder decoder = NimbusJwtDecoder<br>        .withJwkSetUri(jwkSetUri)<br>        .build();<br><br>    OAuth2TokenValidator&lt;Jwt&gt; withIssuer =<br>        new JwtIssuerValidator(List.of(<br>            &quot;https://keycloak.internal:8443/realms/myapp&quot;,<br>            &quot;https://keycloak.company.com/realms/myapp&quot;<br>        ));<br><br>    OAuth2TokenValidator&lt;Jwt&gt; combined =<br>    new DelegatingOAuth2TokenValidator&lt;&gt;(withIssuer, <br>    new JwtTimestampValidator());<br>    decoder.setJwtValidator(combined);<br>    return decoder;<br>}</pre><p>Wait — JwtIssuerValidator does not accept a list out of the box. You will need to write a small custom validator that checks against multiple allowed issuers. The point is: be explicit about what you trust, and handle the reality that in containerized environments (Kubernetes, OpenShift), the internal and external URLs for your identity provider will almost certainly differ.</p><p>I have seen this issue cause days of debugging across multiple teams. A 5-minute configuration saves you from a painful production incident.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=03ea61f6fcc7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Database Migration Nobody Warns You About — PostgreSQL vs SQL Server Type Mapping]]></title>
            <link>https://medium.com/@emre.dursun0022/the-database-migration-nobody-warns-you-about-postgresql-vs-sql-server-type-mapping-e895535c8f0a?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/e895535c8f0a</guid>
            <category><![CDATA[jpa]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[hibernate]]></category>
            <category><![CDATA[sql-server]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 08:29:09 GMT</pubDate>
            <atom:updated>2026-03-10T08:29:09.580Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have ever needed your Spring Boot application to support both PostgreSQL and SQL Server from the same codebase, you know this pain: the boolean type.</p><p>PostgreSQL has a native boolean type. SQL Server does not — it uses bit. And Hibernate maps Java boolean differently depending on the dialect. This sounds trivial until you realize that:</p><ol><li>Hibernate’s BooleanType generates boolean in DDL for PostgreSQL and bit for SQL Server — so far so good.</li><li>But native queries break. Writing WHERE active = true works in PostgreSQL and fails in SQL Server (it expects WHERE active = 1).</li><li>JPQL handles this, but the moment you use @Query(nativeQuery = true) — which is almost inevitable for complex reporting queries — you are locked to one dialect.</li></ol><p>In a project where we had to maintain cross-database compatibility, the cleanest solution was not a Hibernate trick. It was a convention:</p><pre>@Column(columnDefinition = &quot;smallint&quot;)<br>private boolean active;</pre><p>We mapped all booleans to smallint, which both databases handle identically. Then in native queries, WHERE active = 1 works everywhere. Yes, you lose some type safety at the database level. But you gain something more valuable: predictable behavior across environments.</p><p>The broader lesson here is that JPA’s “database independence” promise has real boundaries. The moment you use native queries, database-specific functions, or advanced constraints, you are stepping outside that abstraction. Knowing exactly where that boundary sits — and planning for it — is what separates a prototype from a production system.</p><p>This kind of cross-database thinking becomes critical when your application runs in heterogeneous environments or when different clients have different database requirements. Do not let the ORM fool you into thinking the database does not matter.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e895535c8f0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The RabbitMQ Mistake That Costs You Messages in Production]]></title>
            <link>https://medium.com/@emre.dursun0022/the-rabbitmq-mistake-that-costs-you-messages-in-production-b5574864e04e?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5574864e04e</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[messaging]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Tue, 10 Mar 2026 08:28:55 GMT</pubDate>
            <atom:updated>2026-03-10T08:28:55.881Z</atom:updated>
            <content:encoded><![CDATA[<p>I have managed RabbitMQ in production for over 4 years, and the single most dangerous misconfiguration I have seen is this: publishers that do not use Publisher Confirms.</p><p>Here is how it usually goes: you publish a message to RabbitMQ, the method returns successfully, and you move on. Everything looks fine in development. Then in production, under load, the broker restarts, a network blip happens, or a queue hits its memory limit — and your message is silently dropped. No exception. No log. Just gone.</p><p>The default channel.basicPublish() is fire-and-forget. The broker does not guarantee it received the message unless you explicitly ask it to confirm.</p><p>In Spring Boot, enabling this is deceptively simple:</p><pre>spring:<br>  rabbitmq:<br>    publisher-confirm-type: correlated<br>    publisher-returns: true</pre><pre>rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -&gt; {<br>    if (!ack) {<br>        log.error(&quot;Message not confirmed: {}&quot;, cause);<br>        // Retry or persist to fallback store<br>    }<br>});</pre><p>But here is the part that most tutorials skip: Publisher Confirms are asynchronous. The confirm callback fires on a different thread than your publisher. This means if you need to correlate a failed confirmation back to the original business event, you need to pack meaningful data into the CorrelationData — not just a UUID.</p><p>During our RabbitMQ migration from 3.9 to 4.1, we also discovered that Quorum Queues (the modern replacement for mirrored classic queues) handle confirms differently. They only confirm once the message is replicated to a majority of nodes. This is safer, but it means your confirm latency increases with cluster size. If you are batching publishes and waiting for confirms, you need to account for this in your timeout settings.</p><p>Reliable messaging is not about the happy path. It is about what happens in the 30 seconds when everything goes wrong.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5574864e04e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtual Threads Changed How I Think About Thread Pools]]></title>
            <link>https://medium.com/@emre.dursun0022/virtual-threads-changed-how-i-think-about-thread-pools-15524bbc1028?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/15524bbc1028</guid>
            <category><![CDATA[project-loom]]></category>
            <category><![CDATA[virtual-threads]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[java21]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Sat, 07 Mar 2026 12:28:30 GMT</pubDate>
            <atom:updated>2026-03-07T12:30:18.883Z</atom:updated>
            <content:encoded><![CDATA[<p>When we migrated our platform from Java 11 to Java 21, I was most excited about one thing: Virtual Threads (Project Loom).</p><p>But here is what nobody tells you — simply replacing Executors.newFixedThreadPool(200) with Executors.newVirtualThreadPerTaskExecutor() is not the whole story. It can actually make things worse if you are not careful.</p><p>In our aviation management system, we had a service that processes real-time turnaround events from 9 airports simultaneously. The old approach used a fixed pool of 200 platform threads. When we switched to virtual threads, throughput initially improved — and then our PostgreSQL connection pool started hitting its ceiling. We were suddenly running 2,000+ concurrent database calls instead of 200.</p><p>The realization was this: platform threads were acting as a natural throttle on our system. Fixed pool size = implicit backpressure. Virtual threads removed that throttle entirely.</p><p>The solution was to introduce a Semaphore at the database boundary:</p><pre>private static final Semaphore DB_PERMITS = new Semaphore(100);</pre><pre>public FlightData fetchFlight(String flightId) {<br>    DB_PERMITS.acquire();<br>    try {<br>        return repository.findByFlightId(flightId);<br>    } finally {<br>        DB_PERMITS.release();<br>    }<br>}</pre><p>Virtual threads give you cheap concurrency. But concurrency without backpressure is a denial-of-service attack on your own infrastructure. The real migration is not just changing the executor — it is rethinking where your bottlenecks sit and guarding them explicitly.</p><p>After this migration, we measured a 25% improvement in overall application performance. Not because virtual threads are magic, but because they forced us to identify the real constraints in our system and address them intentionally.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15524bbc1028" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Hibernate Flush You Never Saw Coming]]></title>
            <link>https://medium.com/@emre.dursun0022/the-hibernate-flush-you-never-saw-coming-484ad6bdf3f1?source=rss-89c2acfa4865------2</link>
            <guid isPermaLink="false">https://medium.com/p/484ad6bdf3f1</guid>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-jpa]]></category>
            <category><![CDATA[hibernate]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Emre Dursun]]></dc:creator>
            <pubDate>Sat, 07 Mar 2026 12:25:05 GMT</pubDate>
            <atom:updated>2026-03-07T12:30:46.563Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever had a Hibernate query that was painfully slow, but the SQL looked perfectly fine?</p><p>Here is something that trips up even experienced developers: Hibernate’s auto-flush behavior before queries. When you call entityManager.createQuery(), Hibernate checks if there are dirty entities in the persistence context that could affect the query result. If there are, it flushes them to the database first — silently generating UPDATE statements you never asked for.</p><p>In a high-traffic aviation system I work on, we had a service that loaded a batch of flight records, modified some fields, and then ran a separate read query in the same transaction. That read query was taking 400ms when it should have taken 20ms. The culprit? Hibernate was flushing 200+ dirty entities before executing our SELECT.</p><p>The fix was straightforward but easy to overlook:</p><pre>entityManager.createQuery(&quot;SELECT f FROM Flight f WHERE ...&quot;)<br>    .setFlushMode(FlushModeType.COMMIT)<br>    .getResultList();</pre><p>By setting the flush mode to COMMIT, we told Hibernate: “Don’t flush now, wait until the transaction commits.” The query dropped from 400ms to 18ms.</p><p>But here is the deeper lesson — this is not just a performance trick. It changes your data visibility. If your query depends on the uncommitted changes you just made in the same transaction, COMMIT flush mode will return stale data. You have to consciously decide: do I need consistency within this transaction, or do I need speed?</p><p>After 8 years of working with JPA in production, my rule of thumb is: if the read query and the write operation target different entity types (or unrelated tables), FlushModeType.COMMIT is almost always safe. If they touch the same table, keep AUTO and pay the flush cost.</p><p>Small detail. Massive impact in real systems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=484ad6bdf3f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>