{"id":5076,"date":"2024-08-21T12:07:14","date_gmt":"2024-08-21T12:07:14","guid":{"rendered":"https:\/\/www.aegissofttech.com\/insights\/?p=5076"},"modified":"2026-03-18T11:22:54","modified_gmt":"2026-03-18T11:22:54","slug":"balancing-consistency-spring-boot-caching-partitioning-schedulers","status":"publish","type":"post","link":"https:\/\/www.aegissofttech.com\/insights\/balancing-consistency-spring-boot-caching-partitioning-schedulers\/","title":{"rendered":"Balancing Consistency &amp; Performance in Spring Boot with Caching, Partitioning, &amp; Schedulers"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Introduction<\/strong>:<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this blog, you will learn about how to balance consistency and Performance with strategic Use of caching, database partitioning, and Scheduler in spring Boot microservices:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the trend of microservices, to optimize performance at the same time to maintain data consistency is really a major challenge. Spring Boot microservices also has same challenges. One effective way to achieve this balance between performance n data consistency during high traffic is through strategic caching.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Caching can reduce latency and decrease the load on our microservices as it stores frequently accessed data of the client. In this blog, I have explained the principles of caching in Spring Boot microservices with a complex real-time <a href=\"https:\/\/www.aegissofttech.com\/java-application-development-services.html\">Java application development services<\/a> example implementation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Concepts of Caching in Microservices<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Caching is a way used to store copies of frequently accessed data in a Cache (i.e. a temporary storage area, allowing for faster data retrieval. It reduces the need to frequently fetch the same data from the main source, such as a primary database or an enterprise <a href=\"https:\/\/www.aegissofttech.com\/data-warehouse-services\" target=\"_blank\" rel=\"noreferrer noopener\">data warehousing<\/a> platform, where repeated high-volume queries can be resource-intensive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Major Benefits of Caching:<\/strong><\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Performance gets Improved<\/strong>: It reduces API response time by fetching data from the cache instead of making every time database or API calls.<\/li>\n\n\n\n<li><strong>Load gets reduced<\/strong>: It reduces or decreases the load on the backend services as well as on databases side so that resources get less occupied and they can be used for other operations.<\/li>\n\n\n\n<li><strong>Scalability gets enhanced<\/strong>: It increases the scalability of microservices as it can serve more requests with lower latency.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Diff. Types of Caching:<\/strong><\/h2>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>In-Memory Caching<\/strong>: With this type of caching, it stores data in the RAM so that access time is fast. For examples; Ehcache and Caffeine.<\/li>\n\n\n\n<li><strong>Distributed Caching<\/strong>: With this type of caching, data is stored across multiple nodes so that scalability is increased as well as fault tolerance is achieved. For Example :Redis and Hazelcast.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Achieving balance btw Consistency and Performance<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">See as you know caching increases performance nd as a result stale data is also increased if we are not managing these correctly. So at some point we have to maintain a balance between data consistency and performance and it should be must. Below are some strategies I have explained:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Invalidate Cache<\/strong>: &nbsp;We have to always make sure that whatever cached data that should get invalidated or updated whenever the underlying data gets changed.<\/li>\n\n\n\n<li><strong>Time-to-Live (TTL)<\/strong>: One more thing is to set an cache expiration time for the cached data so that after that many intervals again fresh cache is populated.<\/li>\n\n\n\n<li><strong>Read-Through Caching and Write-Through<\/strong>: With this configuration,&nbsp; cache gets synchronized with the data source during every read and write operations.<\/li>\n\n\n\n<li><strong>Event-Driven Caching<\/strong>: Best practice is to leverage events to update or invalidate the cache data\/entries whenever there is a change happens in the data source.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Real-Time Example Implementation for Strategic Caching with Spring Boot Microservice<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I have explained here a real-time example of an e-commerce application where we need to optimize product catalog service performance using strategic caching.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Setting Up the Project<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First basic step is to create a Spring Boot project with the required dependencies. Add below dependencies to your pom.xml:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"841\" height=\"214\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Project.png\" alt=\"\" class=\"wp-image-5077\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Project.png 841w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Project-300x76.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Project-768x195.png 768w\" sizes=\"(max-width: 841px) 100vw, 841px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Configuring Redis Cache<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Configure Redis as the caching solution in application.properties:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"405\" height=\"109\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configuring-Redis-Cache.png\" alt=\"\" class=\"wp-image-5078\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configuring-Redis-Cache.png 405w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configuring-Redis-Cache-300x81.png 300w\" sizes=\"(max-width: 405px) 100vw, 405px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Enabling Caching in Spring Boot<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Enable caching by annotating the main application class:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" width=\"912\" height=\"178\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Enabling-Caching-in-Spring-Boot.png\" alt=\"\" class=\"wp-image-5079\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Enabling-Caching-in-Spring-Boot.png 912w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Enabling-Caching-in-Spring-Boot-300x59.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Enabling-Caching-in-Spring-Boot-768x150.png 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Implementing Cacheable Methods<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use below annotations with @Cacheable, @CachePut, and @CacheEvict to manage caching behavior.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Service Class Example:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"394\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Service-Class-Example-1024x394.png\" alt=\"\" class=\"wp-image-5080\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Service-Class-Example-1024x394.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Service-Class-Example-300x116.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Service-Class-Example-768x296.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Service-Class-Example.png 1342w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>@Cacheable: Caches the result of getDemoProductById method calls. If the method is called with the same productId, the cached value is returned.<\/li>\n\n\n\n<li>@CachePut: Updates the cache whenever a product is updated.<\/li>\n\n\n\n<li>@CacheEvict: Removes the product from the cache when it is deleted.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Managing Cache Consistency<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To ensure cache consistency, configure cache invalidation and synchronization strategies:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example of Cache Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1023\" height=\"358\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Example-of-Cache-Configuration.png\" alt=\"\" class=\"wp-image-5081\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Example-of-Cache-Configuration.png 1023w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Example-of-Cache-Configuration-300x105.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Example-of-Cache-Configuration-768x269.png 768w\" sizes=\"(max-width: 1023px) 100vw, 1023px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>TTL<\/strong>: Here for example , we are setting a time-to-live (TTL) of 10 minutes for cache entries and that\u2019s why cached data remains fresh after every 10 minutues, cache is get repopulated.<\/li>\n\n\n\n<li><strong>Caching Null Values is disabled<\/strong>: With this config, it would prevent null values from being cached.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Testing and Monitoring<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Final thing is to test the above caching example implementation and verify that it &nbsp;really improves performance and maintains data consistency. For this testing, you can use&nbsp; Spring Boot Actuator and monitoring features with spring boot admin to monitor cache hits and cache evictions<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Strategic caching in Spring Boot microservices really enhances performance. By implementing caching with Redis, which provides a robust caching framework, and using common annotations such as @Cacheable, @CachePut, and @CacheEvict, we can optimize your microservices. This approach is a crucial part of <a href=\"https:\/\/www.aegissofttech.com\/microservices-consulting-services.html\">Microservices Development Services<\/a> to ensure high efficiency and scalability.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What are Real-Time Caching Strategies for Spring Boot: How can we achieve Performance and Consistency in Microservices with real time example implementation:<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Caching Strategies?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before diving into the implementation, it\u2019s essential to understand the different caching strategies available:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Cache-aside or (Lazy Loading)<\/strong><\/li>\n\n\n\n<li><strong>Write-through<\/strong><\/li>\n\n\n\n<li><strong>Write-behind (Write-back)<\/strong><\/li>\n\n\n\n<li><strong>Read-through<\/strong><\/li>\n\n\n\n<li><strong>Distributed Caching<\/strong><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Cache-aside (Lazy Loading)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this cache-aside pattern, the application first checks the cache for specific data. If lets say &nbsp;the data is not found then in caching terminology it is (cache miss), so then if a cache miss happens. it retrieves the data from the database and again populates it in the cache and &nbsp;then give response<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Write-through<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this write-through way, data is first written to the cache and the database at same time. This makes data consistency between the cache and the database.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Write-behind (Write-back)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In thid write-behind approach, data is written to the cache first and then asynchronously it writes to the database. This improves write performance but problem is it requires proper handling of &nbsp;data loss scenarios.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Read-through<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this read-through approach, the cache is a proxy to the underlying data store. Whatever the read requests comes, that goes through the cache where data gets loaded from the database if it is not already cached.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Distributed Caching<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In this distributed caching approach, it spreads the cache across multiple nodes\/clusters to improve scalability and fault tolerance. Frequently used distributed caching solutions are examples: Redis , Hazelcast and Apache Ignite.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to implement Cache-aside Strategy in Spring Boot Microservices<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this example I have explained about real-time implementation using the cache-aside apprach in a Spring Boot microservices architecture. I am using Redis here as our caching solution<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Scenario :<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Lets consider an example of microservices-based e-commerce application with two services: one is lets say Aegis Softtech Product Service and Inventory Service. The Product Service will fetch product details and the Inventory Service will manage product stock levels. I am going to implement caching for the Product Service to optimize performance while fetching product details.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step-by-Step Implementation<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 1: Setup Spring Boot Project<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Start with basic springboot project &nbsp;and add the dependencies for Redis and Spring Cache. In pom file<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Maven Dependency:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"847\" height=\"220\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Dependency.png\" alt=\"\" class=\"wp-image-5082\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Dependency.png 847w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Dependency-300x78.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Dependency-768x199.png 768w\" sizes=\"(max-width: 847px) 100vw, 847px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 2: Configure Redis<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Configure Redis in <code>application.properties<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"405\" height=\"109\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Redis.png\" alt=\"\" class=\"wp-image-5083\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Redis.png 405w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Redis-300x81.png 300w\" sizes=\"(max-width: 405px) 100vw, 405px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 3: Enable Caching in Spring Boot<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Then use annotation to enable caching in application by using <code>@EnableCaching<\/code> to our main application class:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">@SpringBootApplication<br>@EnableCaching<br>public class ECommerceDemoApplication {<br>   public static void main(String[] args) {<br>       SpringApplication.run(ECommerceDemoApplication.class, args);<br>}<br>}<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 4: Implement Caching in Product Service<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Create the Product Pojo and repository:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"913\" height=\"274\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implement-Caching-in-Product-Service.png\" alt=\"\" class=\"wp-image-5084\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implement-Caching-in-Product-Service.png 913w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implement-Caching-in-Product-Service-300x90.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implement-Caching-in-Product-Service-768x230.png 768w\" sizes=\"(max-width: 913px) 100vw, 913px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Create the ProductService to handle caching:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"351\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-ProductService-to-handle-caching-1024x351.png\" alt=\"\" class=\"wp-image-5085\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-ProductService-to-handle-caching-1024x351.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-ProductService-to-handle-caching-300x103.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-ProductService-to-handle-caching-768x263.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-ProductService-to-handle-caching.png 1185w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 5: Handle Cache Misses and Evicts<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In the <code>ProductService<\/code>, use the <code>@Cacheable<\/code> annotation to load the product into the cache if it\u2019s not already there (cache miss). Use the <code>@CacheEvict<\/code> annotation to remove outdated data from the cache when a product is updated.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 6: Create Controller for Product Service<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Create a REST controller to expose the product service endpoints:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"324\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Controller-for-Product-Service-1024x324.png\" alt=\"\" class=\"wp-image-5086\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Controller-for-Product-Service-1024x324.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Controller-for-Product-Service-300x95.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Controller-for-Product-Service-768x243.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Controller-for-Product-Service.png 1291w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 7: Testing the Implementation<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Verify n test the caching implementation by fetching product details. The first request will make a call to the database and cache the result. Then subsequent requests will be served from the cache, reducing latency and load on the database.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to implement proper Database Partitioning for popular db postgress and mongo database in Spring Boot microservices ?<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Database partitioning as the name implies that it a strategy for managing large datasets to enhance performance and also scalability will be achieved in applications. For microservices architectures usually data size can grow rapidly and, in this scenario, partitioning would really help to distribute the load and also query performance gets optimized with this and there by system stability is maintained.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;In this blog, I have explained in details about how to implement database partitioning in an efficient way for PostgreSQL and MongoDB in Spring Boot microservices with a real time example impl.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is Database Partitioning?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Database partitioning &nbsp;means it is technique of dividing a large table into smaller data which can be manageable and these smaller data is known as partitions. Each partition can be separately managed and accessed independently. And these data together form a complete larger dataset. We can implement partitioning in several ways:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Sharding \/Horizontal Partitioning<\/strong>: In this process, rows of a table are distributed across multiple tables based on a shard key.<\/li>\n\n\n\n<li><strong>Vertical Partitioning<\/strong>: In this type, table is split into smaller tables with lesser columns.<\/li>\n\n\n\n<li><strong>Range Partitioning<\/strong>: In this type,data are divided &nbsp;based on ranges of values.<\/li>\n\n\n\n<li><strong>List Partitioning<\/strong>: In this type, data gets divided based on some predefined list of values.<\/li>\n\n\n\n<li><strong>Hash Partitioning<\/strong>: &nbsp;In this type, data is distributed using a hash function on a partition key.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Benefits of Partitioning<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Performance boost<\/strong>: Queries will run faster if datasets are smaller.<\/li>\n\n\n\n<li><strong>Scalability<\/strong>: We can easily add new partition to scale up<\/li>\n\n\n\n<li><strong>Maintenance<\/strong>: Simplifies backup, restore, and indexing operations.<\/li>\n\n\n\n<li><strong>Data Management<\/strong>: Facilitates data archival and purging.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">How to implement Partitioning in PostgreSQL<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">PostgreSQL supports all types portioning such as range, list and hash partitioning by default.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;I\u2019ve explained step-by-step to implementing range partitioning in PostgreSQL in a Spring Boot microservices environment.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 1: Define the Partitioning Strategy<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">First find the table and the partition key. Fore xample, partition an <code>orders<\/code> table by <code>order_date<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 2: Create the Parent Table<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here creating a parent table without data but with all required columns.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"162\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-Parent-Table.png\" alt=\"\" class=\"wp-image-5087\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-Parent-Table.png 522w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-the-Parent-Table-300x93.png 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 3: Create Partitioned Tables<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here I am creating child tables for every range.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"591\" height=\"132\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Partitioned-Tables.png\" alt=\"\" class=\"wp-image-5100\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Partitioned-Tables.png 591w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Create-Partitioned-Tables-300x67.png 300w\" sizes=\"(max-width: 591px) 100vw, 591px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 4: Configure Spring Boot Application<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In your Spring Boot application, configure the data source and enable JPA:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>application.properties:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"931\" height=\"264\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Spring-Boot-Application.png\" alt=\"\" class=\"wp-image-5101\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Spring-Boot-Application.png 931w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Spring-Boot-Application-300x85.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Spring-Boot-Application-768x218.png 768w\" sizes=\"(max-width: 931px) 100vw, 931px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Entity Class:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"759\" height=\"295\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Entity-Class.png\" alt=\"\" class=\"wp-image-5102\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Entity-Class.png 759w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Entity-Class-300x117.png 300w\" sizes=\"(max-width: 759px) 100vw, 759px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Repository Interface:<\/strong><br>public interface OrderDemoRepository extends JpaRepository {<br>\/\/ Custom query methods<br>}<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Implementing Partitioning in MongoDB<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For horizontal partitioning, MongoDB uses sharding<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 1: Enable Sharding<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We\u2019ve to enable sharding on the database.<br>sh.enableSharding(&#8220;aegisdb&#8221;)<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 2: Then need to Shard Key and Shard Collection<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Create a shard key and shard the collection.<br>db.orders.createIndex({ odrDate: 1 })<br>sh.shardCollection(&#8220;aegisdb.orders&#8221;, { odrDate: 1 })<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Step 3: Configure Spring Boot Application<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Configure MongoDB settings in your Spring Boot application.<br>application.properties:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"694\" height=\"69\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Spring-Boot-Application2.png\" alt=\"\" class=\"wp-image-5103\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Spring-Boot-Application2.png 694w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Spring-Boot-Application2-300x30.png 300w\" sizes=\"(max-width: 694px) 100vw, 694px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Entity Class:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Same as Order Class<strong><\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Repository Interface:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public<code> <\/code>interface<code> <\/code>OrderDemoRepository<code> <\/code>extends<code> <\/code>MongoRepository<code>&lt;Order, String&gt; {<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&nbsp;&nbsp;&nbsp; <\/code>\/\/ Custom query methods<code><\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How to achieve partitioning in an IoT Microservice<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Scenario:<\/strong> An IoT application for example it collects and processes sensor data from various iot devices. The application uses PostgreSQL for storing transactional data and MongoDB for storing historical sensor data readings.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Effective partitioning strategies means it should manage the large inflow of data and then it should give optimal performance.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Setting Up Spring Boot Project:<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In your spring boot project, add dependencies &nbsp;in pom for PostgreSQL, MongoDB, and Spring Data JPA.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>pom.xml:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"513\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-Spring-Boot-Project.png\" alt=\"\" class=\"wp-image-5104\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-Spring-Boot-Project.png 993w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-Spring-Boot-Project-300x155.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-Spring-Boot-Project-768x397.png 768w\" sizes=\"(max-width: 993px) 100vw, 993px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. PostgreSQL Partitioning Configuration:<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here I am creating partitioned <code>sensor_data<\/code> table in PostgreSQL and here I am using range partitioning based on <code>created_at<\/code> timestamps.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"212\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/PostgreSQL-Partitioning-Configuration-1024x212.png\" alt=\"\" class=\"wp-image-5105\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/PostgreSQL-Partitioning-Configuration-1024x212.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/PostgreSQL-Partitioning-Configuration-300x62.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/PostgreSQL-Partitioning-Configuration-768x159.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/PostgreSQL-Partitioning-Configuration.png 1266w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SensorData Pojo:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"283\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorData-Pojo.png\" alt=\"\" class=\"wp-image-5106\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorData-Pojo.png 724w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorData-Pojo-300x117.png 300w\" sizes=\"(max-width: 724px) 100vw, 724px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SensorData Repository:<br><\/strong>java<br>public interface SensorDataDemoRepository extends JpaRepository {<br>}<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. <strong>MongoDB Sharding Configuration:<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Enable sharding for the historical_readings collection in MongoDB<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Application Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1002\" height=\"279\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Application-Configuration.png\" alt=\"\" class=\"wp-image-5107\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Application-Configuration.png 1002w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Application-Configuration-300x84.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Application-Configuration-768x214.png 768w\" sizes=\"(max-width: 1002px) 100vw, 1002px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>HistoricalReading Document:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"267\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/HistoricalReading-Document.png\" alt=\"\" class=\"wp-image-5108\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/HistoricalReading-Document.png 660w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/HistoricalReading-Document-300x121.png 300w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>HistoricalReading Repository:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public<code> <\/code>interface<code> <\/code>HistoricalSampleReadingRepository<code> <\/code>extends<code> <\/code>MongoRepository<code>&lt;HistoricalSampleReading, String&gt; {<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. Service Layer Implementation:<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Implement a service layer to handle sensor data processing and storage.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SensorService:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"312\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorService-1024x312.png\" alt=\"\" class=\"wp-image-5109\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorService-1024x312.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorService-300x91.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorService-768x234.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorService.png 1417w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. Controller Layer Implementation:<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Create a controller to handle incoming sensor data.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SensorController:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"453\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorController-1024x453.png\" alt=\"\" class=\"wp-image-5110\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorController-1024x453.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorController-300x133.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorController-768x340.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/SensorController.png 1371w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>SensorRequest DTO:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class SensorSampleRequest {\nprivate Integer deviceId;\nprivate Timestamp createdAt;\nprivate BigDecimal temp;\nprivate BigDecimal humid;\nprivate String readings;\n\/\/ getters and setters\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Enhance Performance and Consistency in microservices through Strategic Database Partitioning?<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding Database Partitioning<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Database partitioning as I already mentioned it divides a large database into smaller individual manageable segments called partitions. Each partition can be scaled independently. And we can apply partitioning based on various criteria for ex wr.t range, list, hash or composite keys, depending on the use case.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example implementation E-Commerce Application<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I have explained here about an e-commerce application where multiple microservices serves different purposes including orders, inventory and user\/customer data. The app may face performance bottlenecks and consistency issues with to the large volume of input data and high transaction rates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here, I have Implemented database partitioning which can solve these issues where we are going to distribute the data across multiple partitions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Scenarios:<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Application<\/strong>: e-comm platform with microservices for orders, inventory and user\/customer management.<\/li>\n\n\n\n<li><strong>Challenge<\/strong>: Performance issues and consistency issues with a monolithic database.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Identifying Partitioning Strategy<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">For our example, we&#8217;ll use <strong>range partitioning<\/strong> based on order IDs. This would be suitable for our requirement with large datasets where queries are triggered within specific ranges.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Partitioning Scheme:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Orders Table<\/strong>: Partition based on order ID ranges.\n<ul class=\"wp-block-list\">\n<li>Orders with IDs from 1 to 1,000,00 go into <code>orders_part_1<\/code>. We can increase this to more range also depending upon the volume of input request<\/li>\n\n\n\n<li>Orders with IDs from 1,000,01 to 2,000,00 go into <code>orders_part_2<\/code>, and so on.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Database Schema Setup<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create the Base Table and Partitions:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"406\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Database-Schema-Setup.png\" alt=\"\" class=\"wp-image-5111\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Database-Schema-Setup.png 571w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Database-Schema-Setup-300x213.png 300w\" sizes=\"(max-width: 571px) 100vw, 571px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Base Table<\/strong>: <code>orders<\/code> table is defined with <code>order_id<\/code> as the partitioning key.<\/li>\n\n\n\n<li><strong>Partitions<\/strong>: Diff ranges of <code>order_id<\/code> are assigned to different partitions. This way it would help in distributing the data and also query performance will be optimized.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Spring Boot Configuration<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Update the <\/strong><code><strong>application.properties<\/strong><\/code><strong> for Database Connection:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"793\" height=\"115\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Update-the-application.png\" alt=\"\" class=\"wp-image-5112\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Update-the-application.png 793w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Update-the-application-300x44.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Update-the-application-768x111.png 768w\" sizes=\"(max-width: 793px) 100vw, 793px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Configure Entity and Repository:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Here using the Order entity as already explained above and repository in Spring Boot.<br><\/strong>@Repository<br>public interface OrderDemoRepository extends JpaRepository {<br>List findByCustomerId(Long customerId);<br>}<br>Explanation:<br>\u2022 Entity Configuration: The Order pojo is mapped to the orders table with partitioning.<br>\u2022 Repository: OrderRepository extends JpaRepository for CRUD ops.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. Implementing Service Layer<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Order Service Implementation:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"337\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation.png\" alt=\"\" class=\"wp-image-5113\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation.png 972w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation-300x104.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation-768x266.png 768w\" sizes=\"(max-width: 972px) 100vw, 972px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation<\/strong>:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Service Layer<\/strong>: This has service methods to interact with the <code>Order<\/code> repository mainly for query execution and data creation.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. Handling Consistency<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To ensure consistency across partitions in distributed systems we\u2019ve to consider different strategies:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Transactions<\/strong>: Use distributed transactions and check that whatever database &nbsp;you are using that must support partition-level transactions.<\/li>\n\n\n\n<li><strong>Data Integrity<\/strong>: Implement custom validation and impose integrity checks to handle data across partitions.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Example of Consistency Handling:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"972\" height=\"337\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation-1.png\" alt=\"\" class=\"wp-image-5114\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation-1.png 972w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation-1-300x104.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Order-Service-Implementation-1-768x266.png 768w\" sizes=\"(max-width: 972px) 100vw, 972px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Transactional Annotation<\/strong>: Here one thing we have to check that the <code>createOrder<\/code> method is executed within a transaction so that we can maintain data integrity across partitions.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. Monitoring and Maintenance<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">you need to monitor partition performance and adjust partitioning strategy as data size increases. Then use any database monitoring tools to track performance metrics and can verify if any potential issues.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Monitoring Example:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"951\" height=\"261\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Monitoring-Example.png\" alt=\"\" class=\"wp-image-5115\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Monitoring-Example.png 951w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Monitoring-Example-300x82.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Monitoring-Example-768x211.png 768w\" sizes=\"(max-width: 951px) 100vw, 951px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Monitoring Component<\/strong>: Monitors database performance, helping to identify and address potential bottlenecks.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to optimize Consistency and Performance in Spring Boot Microservices with Strategic Scheduling example implementation:<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this blog, I have explained how to optimize consistency and performance in Spring Boot microservices using strategic scheduling. I\u2019ve explained about a real-time complex example with step-by-step process on how to implement these strategies.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Realtime Example Implementation:<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Task Overview:<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Take an example of a retail e-commerce platform where multiple microservices handle various functions as I have already taken same example for other features explanation &nbsp;such as inventory management order process svc and user notifications. One critical challenge is to manage inventory updates and then to send notifications in an effective way that will maintain consistency across microservices<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>Goal:<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Implement a strategic scheduling mechanism to:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Ensure Consistency<\/strong>: Maintain data integrity across all our product order and inventory micro services.<\/li>\n\n\n\n<li><strong>Optimize the Performance<\/strong>: Here we have to improve the performance of scheduled tasks without impacting the overall api responsiveness.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">In details Implementation<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. Setting Up the Spring Boot Project<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Include necessary dependencies in your project for scheduling and data management.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>pom.xml<\/strong><\/code><strong> (Maven Example):<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"826\" height=\"562\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Spring-Boot-Project.png\" alt=\"\" class=\"wp-image-5116\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Spring-Boot-Project.png 826w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Spring-Boot-Project-300x204.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Setting-Up-the-Spring-Boot-Project-768x523.png 768w\" sizes=\"(max-width: 826px) 100vw, 826px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Configure Scheduling<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Next step is to enable scheduling in our Spring Boot main application and then we have to define a scheduler for periodic tasks.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>Application.java<\/strong><\/code><strong>:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"825\" height=\"210\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Scheduling.png\" alt=\"\" class=\"wp-image-5117\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Scheduling.png 825w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Scheduling-300x76.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Configure-Scheduling-768x195.png 768w\" sizes=\"(max-width: 825px) 100vw, 825px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>@EnableScheduling<\/strong><\/code>: This annotation is to enable the scheduler \/ tasks, &nbsp;and&nbsp; allows to define scheduling related methods that execute at specific intervals.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Implementing a Scheduler for Inventory Updates<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here I have created a scheduler to periodically update inventory data so that we can maintain consistency across services.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>InventoryScheduler.java<\/strong><\/code><strong>:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"805\" height=\"292\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implementing-a-Scheduler-for-Inventory-Updates.png\" alt=\"\" class=\"wp-image-5118\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implementing-a-Scheduler-for-Inventory-Updates.png 805w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implementing-a-Scheduler-for-Inventory-Updates-300x109.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implementing-a-Scheduler-for-Inventory-Updates-768x279.png 768w\" sizes=\"(max-width: 805px) 100vw, 805px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>@Scheduled(cron = \"0 0 * * * ?\")<\/strong><\/code>: This configuration makes the method to run every hour at the top of the hour. We can change the cron expression as needed for your use case.<\/li>\n\n\n\n<li><code><strong>updateInventoryLevels<\/strong><\/code>: This method in <code>InventoryService<\/code> updates inventory data.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. Implementing the Inventory Service<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">I have created the <code>InventoryService<\/code> to manage inventory updates and ensure consistency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>InventoryService.java<\/strong><\/code><strong>:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"516\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryService-1024x516.png\" alt=\"\" class=\"wp-image-5119\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryService-1024x516.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryService-300x151.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryService-768x387.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryService.png 1038w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>@Transactional<\/strong><\/code>: We have to be careful here as we need to verify that inventory updates are executed within a transaction for data consistency even if any failures happens.<\/li>\n\n\n\n<li><code><strong>inventoryRepository.save(inventory)<\/strong><\/code>: This will save the updated inventory data to the database.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. Implementing a Scheduler for User Notifications<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">I have defined &nbsp;a scheduler for sending user notifications with a scheduled cron job<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>NotificationScheduler.java<\/strong><\/code><strong>:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"399\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/NotificationScheduler.png\" alt=\"\" class=\"wp-image-5120\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/NotificationScheduler.png 906w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/NotificationScheduler-300x132.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/NotificationScheduler-768x338.png 768w\" sizes=\"(max-width: 906px) 100vw, 906px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>@Scheduled(cron = \"0 0 8 * * ?\")<\/strong><\/code>: With this config, the method will be invoked daily at 8 AM, balancing the load on the system.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. Implementing the Notification Service<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">I have created the <code>NotificationService<\/code> to handle the notification logic.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>NotificationService.java<\/strong><\/code><strong>:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"733\" height=\"238\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implementing-the-Notification-Service.png\" alt=\"\" class=\"wp-image-5121\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implementing-the-Notification-Service.png 733w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Implementing-the-Notification-Service-300x97.png 300w\" sizes=\"(max-width: 733px) 100vw, 733px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>sendSampleDailyNotifications<\/strong><\/code>: This has the logic for sending notifications. This also can be leveraged to fetche user data and then send emails or push notifications.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>7. Monitoring and Performance Tuning<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have to monitor scheduled tasks and then can change the scheduling strategy based on performance metrics.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Monitoring:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>We can leverage Actuator and can impose custom monitoring solutions where we can track the execution of scheduled tasks.<\/li>\n\n\n\n<li>check metrics to find execution time success\/failure rates<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What are Real-Time Strategies for Balancing Performance and Consistency usung&nbsp; Batch Processing in microservices?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In your microservices architecture, how can you balance performance and consistency and it is really a challenge. Batch processing can be imposed here as it is strategy to address this issue specifically consider scenarios where we requires high-throughput operations &nbsp;and where data integrity should be must.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this blog, I have clearly explained with example where we can achieve performance and consistency using batch processing in Spring Boot microservices<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Realtime Example Implementation:<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Scenario:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Again, let\u2019s take same example of an e-commerce app where handle high volumes of order processing and inventory updates are required. The application consists of several microservices such as Order Service and an Inventory Service. I have explained batch processing for managing inventory updates when order is placed.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1. Add Dependency<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">I have created spring boot project with dependencies for batch processing with Kafka and database.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Maven Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"892\" height=\"547\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Configuration.png\" alt=\"\" class=\"wp-image-5122\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Configuration.png 892w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Configuration-300x184.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Maven-Configuration-768x471.png 768w\" sizes=\"(max-width: 892px) 100vw, 892px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>spring-boot-starter-batch<\/strong><\/code>: it is used for the batch processing capabilities.<\/li>\n\n\n\n<li><code><strong>spring-kafka<\/strong><\/code>: &nbsp;it is used to integrate with Kafka for event-driven processing.<\/li>\n\n\n\n<li><code><strong>spring-boot-starter-data-jpa<\/strong><\/code> and <code><strong>h2<\/strong><\/code>: provides database access so that data can be persisted and managed.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">2. Defining the Batch Processing Job<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Batch processing in Spring Boot &nbsp;is achieved using <code>Job<\/code> and <code>Step<\/code> configurations. I have defiend a job that would process the orders in batches and then it will update inventory accordingly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Job Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"509\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Job-Configuration-1024x509.png\" alt=\"\" class=\"wp-image-5123\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Job-Configuration-1024x509.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Job-Configuration-300x149.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Job-Configuration-768x382.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Job-Configuration.png 1425w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>inventoryUpdateJob<\/strong><\/code>: Defines a job named <code>inventoryUpdateJob<\/code>, which increments the run ID on each execution.<\/li>\n\n\n\n<li><code><strong>orderStep<\/strong><\/code>: Creates a step that processes orders in chunks of 10.<\/li>\n\n\n\n<li><code><strong>orderProcessor<\/strong><\/code>: Converts orders into inventory updates.<\/li>\n\n\n\n<li><code><strong>inventoryWriter<\/strong><\/code>: Writes inventory updates to the database.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">3. Implementing the Processor and Writer<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>OrderItemProcessor:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"203\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/OrderItemProcessor-1024x203.png\" alt=\"\" class=\"wp-image-5124\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/OrderItemProcessor-1024x203.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/OrderItemProcessor-300x59.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/OrderItemProcessor-768x152.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/OrderItemProcessor.png 1120w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>OrderSampleItemProcessor<\/strong><\/code>: This will convert <code>Order<\/code> objs into <code>InventoryUpdate<\/code> objects so that inventory quantities can be adjusted based on order data.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>InventoryItemWriter:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"380\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter-1024x380.png\" alt=\"\" class=\"wp-image-5125\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter-1024x380.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter-300x111.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter-768x285.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter.png 1126w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>InventoryItemWriter<\/strong><\/code>: this updates the inventory in the database based on the batch of <code>InventoryUpdate<\/code> obj. It retrieves current inventory stock level &amp; then will apply the updates and saves the changes.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">4. Integrating Kafka for Asynchronous Processing<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">To enhance performance, I have used Kafka to handle asynchronous inventory updates.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Kafka Producer Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"271\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Producer-Configuration-1024x271.png\" alt=\"\" class=\"wp-image-5126\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Producer-Configuration-1024x271.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Producer-Configuration-300x79.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Producer-Configuration-768x203.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Producer-Configuration.png 1534w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>KafkaProducerConfig<\/strong><\/code>: This config class has Kafka producer properties where we can send <code>InventoryUpdate<\/code> messages.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Updating InventoryItemWriter to Send Messages to Kafka:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1015\" height=\"307\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter2.png\" alt=\"\" class=\"wp-image-5127\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter2.png 1015w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter2-300x91.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/InventoryItemWriter2-768x232.png 768w\" sizes=\"(max-width: 1015px) 100vw, 1015px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>InventoryItemWriter<\/strong><\/code>: This is used to send inventory updates as Kafka payloads instead of directly writing to the database. This approach really decouples the processing and storage where system\u2019s scalability is increased and system will become resilient.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">5. Handling Kafka Messages in a Consumer Service<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">I have created a Kafka consumer to process inventory updates asynchronously:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Kafka Consumer Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"368\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Consumer-1024x368.png\" alt=\"\" class=\"wp-image-5128\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Consumer-1024x368.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Consumer-300x108.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Consumer-768x276.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Kafka-Consumer.png 1354w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>KafkaConsumerConfig<\/strong><\/code>: This configuration will make Kafka consumer to read <code>InventoryUpdate<\/code> messages from the <code>inventory-updates<\/code> topic.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>InventoryUpdateConsumer:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"321\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Explanation-1024x321.png\" alt=\"\" class=\"wp-image-5129\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Explanation-1024x321.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Explanation-300x94.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Explanation-768x241.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Explanation.png 1161w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code><strong>InventoryUpdateConsumer<\/strong><\/code>: This consumer will listen to the <code>inventory-updates<\/code> topic and processes incoming <code>InventoryUpdate<\/code> messages so that inventory levels update will happen asynchronously.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to achieve Performance and Consistency in Spring Boot Microservices with use of Scheduling and Batch Processing?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here, &nbsp;I have explained with an example how to implement scheduling and batch processing within a single project using Spring boot microservices. Explained real-time scenario of a financial services application where showed examples of transactions and reporting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Example impl for Financial Transaction Processing App<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In a financial services application, primary thing is to handle periodic tasks consists of generating daily transaction reports and then processing transactions in large batches. I have used Spring Boot\u2019s scheduling and batch processing features.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Project goal<\/strong><\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Daily Transaction Reporting<\/strong>: The app will generate and email daily transaction reports in a specified time.<\/li>\n\n\n\n<li><strong>Processing the Transaction in batches<\/strong>: It will process a large batch of financial transactions.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step-by-Step Implementation<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>1. &nbsp;Basic Setup<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Basic setup you will be aware about to create a Spring Boot project &nbsp;and then add necessary maven\/gradle dependencies for scheduling and batch packages.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>build.gradle for Gradle:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"961\" height=\"112\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/for-Gradle.png\" alt=\"\" class=\"wp-image-5130\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/for-Gradle.png 961w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/for-Gradle-300x35.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/for-Gradle-768x90.png 768w\" sizes=\"(max-width: 961px) 100vw, 961px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>2. Batch Processing Configuration<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Spring Batch here helps in processing large volumes of data. I have configured a simple batch job to handle transaction reconciliation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Batch Job Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"624\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Batch-Job-Configuration-1024x624.png\" alt=\"\" class=\"wp-image-5131\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Batch-Job-Configuration-1024x624.png 1024w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Batch-Job-Configuration-300x183.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Batch-Job-Configuration-768x468.png 768w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Batch-Job-Configuration.png 1354w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>@EnableBatchProcessing<\/strong>: This annotation will enable Spring Batch features.<\/li>\n\n\n\n<li><strong>Job and <\/strong><strong>Step Beans<\/strong>: We have to create a job and &nbsp;define the steps for processing transactions. A job actually consists of one or more steps and &nbsp;each step denotes &nbsp;a chunk of data.<\/li>\n\n\n\n<li><strong>ItemProcessor<\/strong>: It will process each Transaction object to create a ProcessedTransaction.<\/li>\n\n\n\n<li><strong>ItemWriter<\/strong>: This helps in writing the processed transactions to the specified target output .<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>3. Scheduling Configuration<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">I\u2019ve used &nbsp;springboot scheduling features to trigger the batch job and other periodic tasks like generating reports.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Scheduling Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"883\" height=\"645\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Scheduling-Configuration.png\" alt=\"\" class=\"wp-image-5132\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Scheduling-Configuration.png 883w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Scheduling-Configuration-300x219.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Scheduling-Configuration-768x561.png 768w\" sizes=\"(max-width: 883px) 100vw, 883px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>4. Transactional Consistency<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In this below class, I am ensuring that consistency is achieved by specifying transactional boundaries within the configuration class for batch processing. Spring Batch config is used here to provide in-built support to manage transactions across job steps.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Transactional Management:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"981\" height=\"420\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Transactional-Management.png\" alt=\"\" class=\"wp-image-5133\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Transactional-Management.png 981w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Transactional-Management-300x128.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Transactional-Management-768x329.png 768w\" sizes=\"(max-width: 981px) 100vw, 981px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>transactionManager()<\/strong>: We have to create the transaction manager here for managing transactions during &nbsp;the activity for batch processing. For real &nbsp;time apps, we have to configure proper transaction manager.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>5. Error Handling and Retries<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">I have implemented error handling and retry mechanisms here which is really required to manage failures at time of batch processing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Error Handling and Retry Configuration:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"889\" height=\"262\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Error-Handling-and-Retry-Configuration.png\" alt=\"\" class=\"wp-image-5134\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Error-Handling-and-Retry-Configuration.png 889w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Error-Handling-and-Retry-Configuration-300x88.png 300w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Error-Handling-and-Retry-Configuration-768x226.png 768w\" sizes=\"(max-width: 889px) 100vw, 889px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>faultTolerant()<\/strong>: for enabling fault tolerance for the step.<\/li>\n\n\n\n<li><strong>retryLimit(3)<\/strong>: this sets the configuration to retry up to 3 times on exceptions.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>6. Email Notification for Reports<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This configuration is used to send email notifications for daily reports.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Email Configuration:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>application.properties:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"163\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Email-Configuration.png\" alt=\"\" class=\"wp-image-5135\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Email-Configuration.png 691w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Email-Configuration-300x71.png 300w\" sizes=\"(max-width: 691px) 100vw, 691px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Email Service:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"336\" src=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Email-Service.png\" alt=\"\" class=\"wp-image-5136\" style=\"width:1022px;height:auto\" title=\"\" srcset=\"https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Email-Service.png 762w, https:\/\/www.aegissofttech.com\/insights\/wp-content\/uploads\/2024\/08\/Email-Service-300x132.png 300w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Explanation:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>JavaMailSender<\/strong>: Used to send emails.<\/li>\n\n\n\n<li><strong>sendDailyReport()<\/strong>: Sends an email with the report content.<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-text-align-left wp-block-paragraph\"><strong>Tutorial <\/strong>: <a href=\"https:\/\/www.aegissofttech.com\/insights\/kafka-baggage-amp-webflux-migration-to-spring-boot\/\">Kafka migration to Spring Boot<\/a><\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion: <\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The example I explained above for performance and consistency implementation in any microservices based applications in real-time must use a combination of scheduling and batch processing. This would be very much helpful for large-scale data processing and then scheduling tasks for periodic operations and transactional consistency will be achieved<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">Upgrade Java search capabilities with <a href=\"https:\/\/www.aegissofttech.com\/insights\/understanding-vector-databases\/\">Vector Databases<\/a><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":" ","protected":false},"author":12,"featured_media":5144,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[12,49],"tags":[916],"class_list":["post-5076","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","category-microservices","tag-performance-in-spring-boot"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts\/5076","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/comments?post=5076"}],"version-history":[{"count":15,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts\/5076\/revisions"}],"predecessor-version":[{"id":18406,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/posts\/5076\/revisions\/18406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/media\/5144"}],"wp:attachment":[{"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/media?parent=5076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/categories?post=5076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aegissofttech.com\/insights\/wp-json\/wp\/v2\/tags?post=5076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}