Book Image

Design Patterns and Best Practices in Java

By : Kamalmeet Singh, Adrian Ianculescu, Lucian-Paul Torje
Book Image

Design Patterns and Best Practices in Java

By: Kamalmeet Singh, Adrian Ianculescu, Lucian-Paul Torje

Overview of this book

Having a knowledge of design patterns enables you, as a developer, to improve your code base, promote code reuse, and make the architecture more robust. As languages evolve, new features take time to fully understand before they are adopted en masse. The mission of this book is to ease the adoption of the latest trends and provide good practices for programmers. We focus on showing you the practical aspects of smarter coding in Java. We'll start off by going over object-oriented (OOP) and functional programming (FP) paradigms, moving on to describe the most frequently used design patterns in their classical format and explain how Java’s functional programming features are changing them. You will learn to enhance implementations by mixing OOP and FP, and finally get to know about the reactive programming model, where FP and OOP are used in conjunction with a view to writing better code. Gradually, the book will show you the latest trends in architecture, moving from MVC to microservices and serverless architecture. We will finish off by highlighting the new Java features and best practices. By the end of the book, you will be able to efficiently address common problems faced while developing applications and be comfortable working on scalable and maintainable projects of any size.
Table of Contents (15 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

Patterns for resilience


When we are thinking about the resiliency of the application, we should try to answer the following questions: Can the application handle failure conditions? If one component of the application fails, does it bring down the whole application? Is there a single point of failure in the application?

Let's look at some patterns that will help us to make our application resilient.

The circuit-breaker pattern

This is an important pattern to implement both resilience and responsiveness in the system. Often, when a service fails in a system, it impacts other services as well. For example, service X calls service Y in the system to get or update some data. If service Y is unresponsive for some reason, our service X will make a call to service Y, wait for it to timeout, and then fail itself. Think of a scenario where service X itself is called up by another service P, and so on. We are looking at a cascading failure here, which will eventually bring down the whole system.

The circuit...