<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali Farooq</title>
    <description>The latest articles on DEV Community by Ali Farooq (@ali_farooq2165).</description>
    <link>https://dev.to/ali_farooq2165</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2981133%2Fbc413a4f-e740-43c1-b818-6cfbeab5fcdf.jpg</url>
      <title>DEV Community: Ali Farooq</title>
      <link>https://dev.to/ali_farooq2165</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ali_farooq2165"/>
    <language>en</language>
    <item>
      <title>Distributed Caching with Hazelcast + Eureka: Smarter Microservices in Action</title>
      <dc:creator>Ali Farooq</dc:creator>
      <pubDate>Sun, 13 Apr 2025 15:19:16 +0000</pubDate>
      <link>https://dev.to/ali_farooq2165/distributed-caching-with-hazelcast-eureka-smarter-microservices-in-actionpublished-true-2lmp</link>
      <guid>https://dev.to/ali_farooq2165/distributed-caching-with-hazelcast-eureka-smarter-microservices-in-actionpublished-true-2lmp</guid>
      <description>&lt;h1&gt;
  
  
  🧠 Distributed Caching with Hazelcast + Eureka: Smarter Microservices in Action
&lt;/h1&gt;

&lt;p&gt;Hey devs! 👋&lt;br&gt;
If you're working with microservices, you’ve probably hit the classic challenge: &lt;strong&gt;how do we implement an efficient distributed caching solution&lt;/strong&gt; without overloading the database or dealing with complex network setups?&lt;/p&gt;

&lt;p&gt;Let me introduce you to a simple but powerful combo I’ve been playing with — &lt;strong&gt;Hazelcast + Eureka&lt;/strong&gt; — and show you how I integrated them in my project:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/alif2165/HazelcastEurekaDiscovery" rel="noopener noreferrer"&gt;HazelcastEurekaDiscovery on GitHub&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  💡 Why Hazelcast?
&lt;/h2&gt;

&lt;p&gt;Hazelcast is a &lt;strong&gt;distributed in-memory cache&lt;/strong&gt;, and it’s super handy when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want to avoid expensive DB hits
&lt;/li&gt;
&lt;li&gt;You need fast access to session/state data
&lt;/li&gt;
&lt;li&gt;You’re building real-time, low-latency apps
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It supports automatic clustering (nodes discovering each other and sharing data), but out of the box, it uses &lt;strong&gt;multicast&lt;/strong&gt; for discovery — which doesn’t work well in modern cloud environments (like Docker, Kubernetes, AWS, etc.).&lt;/p&gt;


&lt;h2&gt;
  
  
  🔍 Enter Eureka (Service Discovery)
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://github.com/Netflix/eureka" rel="noopener noreferrer"&gt;Eureka&lt;/a&gt; is a &lt;strong&gt;service registry&lt;/strong&gt; from Netflix (supported in Spring Cloud). Services can register themselves, and other services can discover them dynamically. This is perfect for solving the &lt;em&gt;“how do services find each other?”&lt;/em&gt; problem — which Hazelcast needs for clustering.&lt;/p&gt;

&lt;p&gt;So… what if we let Hazelcast use Eureka to discover peer nodes?&lt;/p&gt;

&lt;p&gt;Spoiler: It works great. And that's what my &lt;a href="https://github.com/alif2165/HazelcastEurekaDiscovery" rel="noopener noreferrer"&gt;HazelcastEurekaDiscovery&lt;/a&gt; project is all about.&lt;/p&gt;


&lt;h2&gt;
  
  
  ⚙️ How It Works
&lt;/h2&gt;

&lt;p&gt;Here’s a quick breakdown of what the repo includes:&lt;/p&gt;
&lt;h3&gt;
  
  
  🧱 Components
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Eureka Server&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Hosts the registry at &lt;code&gt;http://localhost:8761&lt;/code&gt;. Services register themselves here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cache Service&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A Spring Boot app with Hazelcast embedded.&lt;br&gt;&lt;br&gt;
It:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Registers with Eureka
&lt;/li&gt;
&lt;li&gt;Uses Eureka to find other cache service instances
&lt;/li&gt;
&lt;li&gt;Forms a Hazelcast cluster dynamically&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  🧪 Run It Yourself
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Clone the repo
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/alif2165/HazelcastEurekaDiscovery
&lt;span class="nb"&gt;cd &lt;/span&gt;HazelcastEurekaDiscovery
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Start Eureka Server
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;eurekaserver
mvn spring-boot:run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Start multiple cache service instances
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ../cacheservice
mvn spring-boot:run &lt;span class="nt"&gt;-Dspring-boot&lt;/span&gt;.run.arguments&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;--server&lt;/span&gt;.port&lt;span class="o"&gt;=&lt;/span&gt;8081
mvn spring-boot:run &lt;span class="nt"&gt;-Dspring-boot&lt;/span&gt;.run.arguments&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nt"&gt;--server&lt;/span&gt;.port&lt;span class="o"&gt;=&lt;/span&gt;8082
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then go to: &lt;code&gt;http://localhost:8761/eureka&lt;/code&gt; to see all registered instances.&lt;/p&gt;
&lt;h3&gt;
  
  
  🧰 Under the Hood: Hazelcast + Eureka Config
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;hazelcast.yaml&lt;/code&gt; example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;network&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;join&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;multicast&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="na"&gt;tcp-ip&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;enabled&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="na"&gt;discovery-strategies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;discovery-strategies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;class-name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;com.hazelcast.discovery.EurekaDiscoveryStrategy&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spring Boot &lt;code&gt;application.properties&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;spring.application.name&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;cacheservice&lt;/span&gt;
&lt;span class="py"&gt;eureka.client.service-url.defaultZone&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;http://localhost:8761/eureka&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  🚀 Why This Rocks
&lt;/h3&gt;

&lt;p&gt;✅ No static IP configs&lt;br&gt;
✅ Scales easily – just start new instances&lt;br&gt;
✅ Cluster auto-formation using Eureka&lt;br&gt;
✅ Cache stays in sync across services&lt;/p&gt;

&lt;p&gt;It’s a clean way to build distributed systems that are scalable, discoverable, and efficient.&lt;/p&gt;




&lt;h3&gt;
  
  
  🎯 Use Cases
&lt;/h3&gt;

&lt;p&gt;Shared caching across microservices&lt;/p&gt;

&lt;p&gt;Lightweight alternative to Redis in some use cases&lt;/p&gt;

&lt;p&gt;In-memory session management&lt;/p&gt;

&lt;p&gt;Cluster coordination without Zookeeper/Consul&lt;/p&gt;




&lt;h3&gt;
  
  
  🙌 Final Thoughts
&lt;/h3&gt;

&lt;p&gt;This setup might be simple, but it solves a real pain point in distributed systems — dynamic, self-forming clusters for shared state.&lt;/p&gt;

&lt;p&gt;If you’re exploring Hazelcast, Spring Cloud, or microservice discovery patterns, give this a try!&lt;/p&gt;

</description>
      <category>springboot</category>
      <category>hazelcast</category>
      <category>microservices</category>
      <category>eureka</category>
    </item>
  </channel>
</rss>
