Tag: Spring Boot

  • How to implement Circuit Breaker Design Pattern in Spring Boot?

    How to implement Circuit Breaker Design Pattern in Spring Boot?

    Table of Contents: Problem: Fault tolerance is a major requirement for enterprise applications. If your application gets huge load , how does it behave? If something wrong happens within your application and you still want to handle it gracefully , what do you do? Fault tolerance is especially important for microservices since many microservices communicate…

  • How to implement SAGA design pattern in Spring Boot?

    How to implement SAGA design pattern in Spring Boot?

    Contents: Problem: Microservices come with their own advantages and disadvantages. One such disadvantage is managing distributed transactions. Let’s say your transaction spans 4 different microservices. How do you ensure that your transaction either commits successfully with all the 4 tasks succeeding or fails successfully if any of the tasks is not completed ( the completed…

  • How to share data across multiple components for a single request in a Spring Boot application?

    How to share data across multiple components for a single request in a Spring Boot application?

    Let’s say that you make a REST API request to a spring boot web application. There is a security requirement that you need to log the user id across all the method calls in the application for this particular request. Something like this: So , if your application flow starts from a controller class and…

  • How to implement Event Sourcing in Spring Boot?

    How to implement Event Sourcing in Spring Boot?

    All our web applications deal with data. We store this data mostly in a database. The data which is stored thus represents the current state of the data. For example , if you have a Customer table the table will have entries which represent the current state of the customer (what their name is and…

  • How to send and receive events through Apache Kafka in Spring Boot?

    Traditionally we have been storing data in database tables. A database row in a table represents the “current state” of an object. And so this is “state driven” programming. This has been serving well for us for decades. It is even a bit inconceivable to think of any other way to store data. But there…

  • How to implement event driven programming in Spring Boot?

    There are several paradigms of programming: Procedural ,Object Oriented , Functional , Event Oriented etc. Each of them comes with their own benefits and disadvantages. Most of the programming done in Java is Object Oriented since the language itself is object oriented. But what if you want to do event driven programming or at the…

  • How to fetch configuration data from config server in Spring Boot?

    Let’s say you have created a Spring Boot application and you fetch properties from application.yml file. Every time you want to change a property you need to restart your application. And if there are few more projects having similar configuration you need to replicate the properties in those applications as well. To solve this ,…

  • How to protect your Spring Boot microservice with OAuth2?

    Protecting your microservice developed in Spring Boot is quite forward. Spring does all the major work for you. Here are the steps to follow: STEP 1: Add spring boot starter oauth2 resource server dependency STEP 2: Configure Authorization Server STEP 3: Test STEP 1: Add spring boot starter oauth2 resource server dependency Add the below…

  • How to set up KeyCloak for OAuth2 client credentials flow?

    We live in the age of microservices. Microservices are often deployed as REST APIs. And the most popular way to protect and access these REST APIs is through OAuth2 protocol. And in OAuth2 protocol ,the preferred way to protect REST APIs is through client credentials. To set this, You first need an Identity and Access…

  • How to copy only updatable values while updating resources through Spring Boot REST API?

    Let’s say you are creating an application to manage your daily tasks. You decide to write REST APIs in Spring Boot. Following REST API conventions , You create an API named /tasks to create a new task using Http POST method. You store the task in database. You create an API with the same name…