Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Free eBook - Hands-On Microservices with Spring Boot and Spring Cloud

4.1 (8 reviews total)
By Magnus Larsson AB
  • A new free eBook every day on the latest in tech
  • 30 permanently free eBooks from our core tech library
  1. Section 1: Getting Started with Microservice Development Using Spring Boot
About this book
Microservices architecture allows developers to build and maintain applications with ease, and enterprises are rapidly adopting it to build software using Spring Boot as their default framework. With this book, you’ll learn how to efficiently build and deploy microservices using Spring Boot. This microservices book will take you through tried and tested approaches to building distributed systems and implementing microservices architecture in your organization. Starting with a set of simple cooperating microservices developed using Spring Boot, you’ll learn how you can add functionalities such as persistence, make your microservices reactive, and describe their APIs using Swagger/OpenAPI. As you advance, you’ll understand how to add different services from Spring Cloud to your microservice system. The book also demonstrates how to deploy your microservices using Kubernetes and manage them with Istio for improved security and traffic management. Finally, you’ll explore centralized log management using the EFK stack and monitor microservices using Prometheus and Grafana. By the end of this book, you’ll be able to build microservices that are scalable and robust using Spring Boot and Spring Cloud.
Publication date:
September 2019
Publisher
Packt
Pages
668
ISBN
9781789613476

 

Introduction to Microservices

This book does not blindly praise microservices. Instead, it's about how we can use their benefits while being able to handle the challenges of building scalable, resilient, and manageable microservices.

As an introduction to this book, the following topics will be covered in this chapter:

  • How I learned about microservices and what experience I have of their benefits and challenges
  • What is a microservice-based architecture?
  • Challenges with microservices
  • Design patterns for handling challenges
  • Software enablers that can help us handle these challenges
  • Other important considerations that aren't covered in this book
 

Technical requirements

No installations are required for this chapter. However, you may be interested in taking a look at the C4 model conventions, https://c4model.com, since the illustrations in this chapter are inspired by the C4 model.

This chapter does not contain any source code.

 

My way into microservices

When I first learned about the concept of microservices back in 2014, I realized that I had been developing microservices (well, kind of) for a number of years without knowing it was microservices I was dealing with. I was involved in a project that started in 2009 where we developed a platform based on a set of separated features. The platform was delivered to a number of customers that deployed it on-premise. To make it easy for the customers to pick and choose what features they wanted to use from the platform, each feature was developed as an autonomous software component; that is, it had its own persistent data and only communicated with other components using well-defined APIs.

Since I can't discuss specific features in this project's platform, I have generalized the names of the components, which are labeled from Component A ...

 

Defining a microservice

To me, a microservice architecture is about splitting up monolithic applications into smaller components, which achieves two major goals:

  • Faster development, enabling continuous deployments
  • Easier to scale, manually or automatically

A microservice is essentially an autonomous software component that is independently upgradeable and scalable. To be able to act as an autonomous component, it must fulfill certain criteria as follows: 

  • It must conform to a shared-nothing architecture; that is, microservices don't share data in databases with each other!
  • It must only communicate through well-defined interfaces, for example, using synchronous services or preferably by sending messages to each other using APIs and message formats that are stable, well-documented, and evolve by following a defined versioning strategy.
  • It must be deployed...
 

Challenges with microservices

In the Challenges with autonomous software components section, we have already seen some of the challenges that autonomous software components can bring (and they all apply to microservices as well) as follows:

  • Many small components that use synchronous communication can cause a chain of failure problem, especially under high load.
  • Keeping the configuration up to date for many small components can be challenging.
  • It's hard to track a request that's being processed and involves many components, for example, when performing root cause analysis, where each component stores log events locally.
  • Analyzing the usage of hardware resources on a component level can be challenging as well.
  • Manual configuration and management of many small components can become costly and error-prone.

Another downside...

 

Design patterns for microservices

This topic will cover using design patterns to mitigate challenges with microservices, as described in the preceding section. Later in this book, we will see how we can implement these design patterns using Spring Boot, Spring Cloud, and Kubernetes.

The concept of design patterns is actually quite old; it was invented by Christopher Alexander back in 1977. In essence, a design pattern is about describing a reusable solution to a problem when given a specific context.  

The design patterns we will cover are as follows: 

  • Service discovery
  • Edge server
  • Reactive microservices
  • Central configuration
  • Centralized log analysis
  • Distributed tracing
  • Circuit Breaker
  • Control loop
  • Centralized monitoring and alarms
This list is not intended to be comprehensive; instead, it's a minimal list of design patterns that are required...
 

Software enablers

As we've already mentioned, we have a number of very good open-source tools that can help us both meet our expectations of microservices and, most importantly, handle the new challenges that come with them:

  • Spring Boot
  • Spring Cloud/Netflix OSS
  • Docker
  • Kubernetes
  •  Istio (a service mesh)

The following table maps the design patterns we will need to handle these challenges, along with the corresponding open-source tool that implements the design pattern:

Design Pattern Spring Boot Spring Cloud Kubernetes Istio

Service discovery

Netflix Eureka and Netflix Ribbon Kubernetes kube-proxy and service resources

Edge server

Spring Cloud and Spring Security OAuth Kubernetes Ingress controller Istio ingress gateway

Reactive microservices

Spring Reactor and Spring WebFlux

Central configuration

Spring Config Server Kubernetes ConfigMaps...
 

Technical requirements

This chapter does not contain any source code that can be downloaded, nor does it require any tools to be installed.

 

Learning about Spring Boot

Spring Boot, and the Spring Framework that Spring Boot is based on, is a great framework for developing microservices in Java.

When the Spring Framework was released in v1.0 back in 2004, it was released in order to fix the overly complex J2EE standard (short for Java 2 Platforms, Enterprise Edition) with its infamous and heavyweight deployment descriptors. Spring Framework provided a much more lightweight development model based on the concept of dependency injection (DI). Spring Framework also used far more lightweight XML configuration files compared to the deployment descriptors in J2EE.

To make things even worse with the J2EE standard, the heavyweight deployment descriptors actually came in two types:
  • Standard deployment descriptors, describing the configuration in a standardized way
  • Vendor-specific deployment descriptors...
About the Author
  • Magnus Larsson AB

    Magnus Larsson has been in the IT industry since 1986, working as a consultant for large companies in Sweden, such as Volvo, Ericsson, and AstraZeneca. In the past, he struggled with the challenges associated with distributed systems. However, these challenges can be handled today with open-source tools such as Spring Cloud, Kubernetes, and Istio. Over the last eight years, Magnus has been helping customers use these tools and has done several presentations and blog posts on the subject.

    Browse publications by this author
Latest Reviews (8 reviews total)
The introduction chapter is great, after that it is really hard to follow.
Muito simples e eficiente o processo de compra .
As a positive point the autor explains a lot of details, however he doesn't use Long Term Support versions in the samples and the way they are organized are too opinionated. A lot of people use Spring Boot (mostly) in a well known MVC model, or at least with some well known structure like Hexagonal Arquitecture.
Recommended For You
Kubernetes and Docker - An Enterprise Guide

Apply Kubernetes beyond the basics of Kubernetes clusters by implementing IAM using OIDC and Active Directory, Layer 4 load balancing using MetalLB, advanced service integration, security, auditing, and CI/CD

By Scott Surovich and 1 more
Solutions Architect's Handbook

From fundamentals and design patterns to the different strategies for creating secure and reliable architectures in AWS cloud, learn everything you need to become a successful solutions architect

By Saurabh Shrivastava and 1 more
40 Algorithms Every Programmer Should Know

Learn algorithms for solving classic computer science problems with this concise guide covering everything from fundamental algorithms, such as sorting and searching, to modern algorithms used in machine learning and cryptography

By Imran Ahmad
Java Coding Problems

Develop your coding skills by exploring Java concepts and techniques such as Strings, Objects and Types, Data Structures and Algorithms, Concurrency, and Functional programming

By Anghel Leonard