HTML
Disclosure: This article may contain affiliate links. When you purchase, we may earn a commission.

Saturday, May 27, 2023

Aggregator Design Pattern In Java Microservices with Examples

The Aggregator design pattern in Microservice architecture is a design pattern used to compose a complex service by aggregating the responses of multiple independent microservices. It's also one of the essential Microservices Design patterns along with SAGA, CQRS, and Event Sourcing. This pattern is proper when a client request requires data or functionality distributed across multiple microservices. It can improve the performance and scalability of the system by allowing each microservice to focus on a specific task and reducing the workload of a single microservice. In this article, we will discuss how the Aggregator Microservice Pattern can be implemented in Java using various approaches, such as asynchronous communication, synchronous communication, or a combination of both. We will also provide examples of code to illustrate each approach.

What is Circuit Breaker Design Pattern in Microservices? How to implement it?

Hello guys, Microservices design patterns are very important concepts for Java developers to learn, not just to create a robust, scalable, and high-performance Microservice architecture but also to do well on Java developer interviews. In the past, I have shared several Microservices design patterns like e Event Sourcing, SAGA, Database Per Microservices, CQRSAPI Gateway, and also shared best practices to design Microservices and in this article, I am going to talk about Circuit-Breaker Design Pattern, and how you can implement in Java using Spring Cloud Framework.  This is not just an important Microservice Pattern but also a popular Microservice question which I have also mentioned earlier in my article about 15 Microservices questions for Interviews. If you haven't read that article yet, I suggest read it, especially if you are preparing for Java and Microservice interviews. 

Friday, May 26, 2023

How to find Kth Smallest Element in a Binary Search Tree? [Solved]

Hello guys, I have been sharing binary search tree-based coding interview questions for quite some time. In the last article, we looked at how to find the maximum sum level in a given binary tree, and in this article, we will find the kth smallest number in a given binary tree like the 5th smallest or 3rd smallest number. Before we find the kth smallest in a Binary search tree, We need to understand the binary search tree. A Binary tree is a data structure in which each node can have at most two children. That is, each node in the binary tree will have data, left child and right child. The first node of the tree is called the Root.

How to find the maximum sum level in binary tree in Java? Example Tutorial

Hello guys, if you are preparing for a coding interview and wondering how to find the maximum sum level in a given binary tree in Java then you have come to the right place. I have been sharing binary tree coding problems for the last few months and in the past, we have seen questions like finding kth smallest element and finding the lowest common ancestor of a binary tree in Java in this article, you will learn how to find the maximum sum level in a given binary tree of integers or numbers. But, before finding the maximum sum level of a binary tree in java, we need to have a good understanding of a binary search tree. Both theoretical knowledge and how to implement binary search tree in Java is important to solve tree-based coding problems

Thursday, May 25, 2023

Difference between application.properties vs Application.json vs Application.yml in Spring Boot

Hello guys, if you have worked in any Spring Boot application then you may have noticed that there are multiple ways to declare configuration for Spring Boot application. I am sure you must have noticed application.propties, application.json, and application.yml while working in proprietary or open source Spring Boot application. When I first started, it was application.propties and it was quite familiar because I have used properties file in past for specify configuration of Java application but when I first see applcation.json and application.yml I was bit confused like what they are and does they really work? In the end I found out that they are just different ways to specify configuration for any Spring Boot application. 

Difference between @RequestParam vs @RequestBody in Spring MVC? (with Example)

Hello everyone, in this article, we are going to look at an interesting topic from the Java Spring framework and the topic is, to find the difference between @RequestBody and @RequestParam. If you don't know this is one of the frequently asked Spring MVC interview question and also two of the most used annotation when creating backend of a Java web application in Spring Framework. Earlier, I have explained difference between @RequestBody and @ResponseBody in Spring MVC and REST APIs, and in this article, I am going to tell you the difference between @RequestBody and @RequestParam annotation in Spring Framework. It is worth noting that these two annotations are frequently used in Spring Boot REST API.

Difference between Spring Boot vs Spring Cloud in Java

Hello guys, if you are wondering, what is difference between Spring Boot and Spring Cloud then you re not alone. Many Java developer are not familiar with various spring boot projects like Spring Security, Spring Data JPA, Spring Batch, Spring Boot, Spring Cloud etc and this lack of knowledge prevent them from taking full advantage of Spring Framework.  In last article, I have explained difference between Spring framework and Spring Boot and in this article we are going to discuss the difference between Spring Boot and Spring Cloud. Before we dive into the difference between the two terms. Let us take a look at different terms like Spring, Spring Boot, and Spring Cloud.

Wednesday, May 24, 2023

10 Examples of RestTemplate in Spring Framework

Hello guys, if you are wondering how to send GET and POST request to your API or Web Service from a Java based Spring Framework then you would be glad to know that You can use use RestTemplate class from Spring Framework. It's a fully functional HTTP client which is really really useful in this age of API. I have used RestTemplate to consume JSON from API before as well as sending different kind of request like POST, PUT, DELETE and PATCH to any REST API. For example, in this article, I shared how to send POST request using RestTemplate and how to set header on HTTP request using RestTemplate. Yes, RestTemplate also allow you to send headers like Authorization on Http Request. 

How to Handle REST exception in Spring Boot Application? Example Tutorial

Hello everyone, in this article we are going to take a look at how to handle REST API exceptions in Spring Boot. It is crucial to handle errors correctly in APIs by displaying meaningful messages as it helps API clients to address problems easily. What happens if we don’t handle the errors manually? By default, the spring application throws a stack trace, which is difficult to understand. Stack traces are mainly for developers hence it is useless for API clients. That's why its very important to use proper HTTP code and error messages to convey errors and exception to client and also logging so that support team can better handle them. Ideally you should tell what went wrong and how to fix it? For example, if the error is due to duplicate data then clearly say, already existed, try with a new one. Similarly, if authentication fail then clearly say authentication failed instead of throwing some other exception.