Book Image

Practical Microservices

By : Umesh Ram Sharma
Book Image

Practical Microservices

By: Umesh Ram Sharma

Overview of this book

<p>A microservice architecture helps you build your application as a suite of different services. This approach has been widely adopted as it helps to easily scale up your application with reduced dependencies. This way if a part of your application is corrupted, it can be fixed easily thereby eliminating the possibility of completely shutting down your software. This book will teach you how to leverage Java to build scalable microservices. You will learn the fundamentals of this architecture and how to efficiently implement it practically.</p> <p>We start off with a brief introduction to the microservice architecture and how it fares with the other architectures. The book dives deep into essential microservice components and how to set up seamless communication between two microservice end points. You will create an effective data model and learn different ways to test and deploy a microservices. You will also learn the best way to migrate your software from a monolith to a microservice architecture.</p> <p>Finishing off with monitoring, scaling and troubleshooting, this book will set a solid foundation for you to start implementing microservices.</p>
Table of Contents (17 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Preface

Microservices is becoming a buzzword in the technology world. It is getting lots of attention among technology enthusiasts, developers, and articles. This book is intended to be a practical guide for developers to write, test, secure, and deploy microservices. It has many benefits and also unique challenges; I intend to shed light on the best practices in an easy-to-read manner, and also to avoid the pitfalls associated with the complexity that can arise due to this architecture.

What this book covers

Chapter 1, Introduction to Microservices Architecture, introduces the overall concepts of a microservices architecture, including a basic definition of what is meant by microservices in this book. The chapter will then quickly move to a high-level walk-through of a comprehensive sample application that will be used throughout the rest of this book.

Chapter 2, Defining Microservice Components, explains the guiding principles to define microservice components, along with teaching how these components form the backbone of the microservices architecture. These guidelines are then made practical by showing how a Spring Boot-based Java project structure can be used to effectively define microservice components. Finally, a sample microservice is used to demonstrate a practical example of Java-based microservice components, along with configuration and a discovery service.

Chapter 3, Communication between Microservice Endpoints, talks about the principles for effective communication between microservices, along with the appropriate reasoning. Options are then introduced for synchronous and asynchronous communication using various technologies ranging from Spring Framework's own capabilities to message brokers. We will also cover how common problems are handled by best practices.

Chapter 4, Securing Microservice Endpoints, discusses common security and security challenges. JWT, OpenID, and OAuth2.0 are introduced for better security in a microservices architecture.

Chapter 5, Creating an Effective Data Model, starts with explaining the difference between creating a microservices-based data model versus a traditional data model and why microservices does it differently. It also explains how data technologies can be intermixed, and how to select the appropriate data management strategy for each microservice component. We will also walk through the sample application data model and explain the various data model decisions and why they were made.

Chapter 6, Testing Microservices, talks about how testing is even more important in a system that is intended to be changed constantly and deployed automatically. However, are our traditional testing approaches and test quality criteria a perfect match for a microservice-style architecture, or do we need to focus on entirely different approaches? Probably a mix of both.

Chapter 7, Deploying Microservices, lets us know that in microservices architecture, we will have a lot to deploy and fairly often. That's one reason to make deployment as painless and easy as possible. Another reason is the fact that we strive for automation and expect our system to be easily scaled up and down, meaning that new microservices are deployed and killed constantly. Docker will help us define and automate the deployment process of microservices.

Chapter 8, Evolving the Existing System, describes the primary mechanisms to evolve a system built on a microservices architecture and how microservices enable such evolution. This chapter will also walk us through an example of how to evolve the sample Java-based application.

Chapter 9, Monitoring and Scaling, describes the key concepts and principles in monitoring and scaling a microservices-based system. This chapter explores the practical approaches to monitoring and scaling Java-based microservices and gives us examples of how to monitor and scale the sample application.

Chapter 10, Troubleshooting, reviews common issues encountered when designing and building a microservices-based architecture and describes common approaches to solve or mitigate them.

What you need for this book

To run examples given in this book, it is recommended that you have a Linux-flavored operating system. You can use Windows or Mac-based systems as well, but the steps described here to install any particular software are explained, keeping the Linux-based system in mind. Other than that, you need to have Maven, Java 8, and any Java-based IDE. It can be Eclipse, IntelliJ, or STS. For the database side, the MySQL community version is recommended.

Who this book is for

This book is for Java developers who want to get started with microservices and implement it in their work place. No knowledge of microservices is necessary.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, path names, dummy URLs, user input, and Twitter handles are shown as follows: "In the /src/main/java/com/sample/firstboot/controller folder, create a called SampleController.java file."

A block of code is set as follows:

@SpringBootApplication
@EnableZuulProxy
public class ApiGatewayExampleInSpring
{
    public static void main(String[] args)    
    {
        SpringApplication.run(ApiGatewayExampleInSpring.class, args);
    }
}

Any command-line input or output is written as follows:

curl http://localhost:8888/userService/default

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "If any user wants to set more specific details regarding the project, then they can see all the configuration settings by clicking on the Switch to the full version button."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.
  2. Hover the mouse pointer on the SUPPORT tab at the top.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box.
  5. Select the book for which you're looking to download the code files.
  6. Choose from the drop-down menu where you purchased this book from.
  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows
  • Zipeg / iZip / UnRarX for Mac
  • 7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Practical-Microservices. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

 

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.