Book Image

Cloud-Native Applications in Java

By : Andreas Olsson, Ajay Mahajan, Munish Kumar Gupta, Shyam Sundar S
Book Image

Cloud-Native Applications in Java

By: Andreas Olsson, Ajay Mahajan, Munish Kumar Gupta, Shyam Sundar S

Overview of this book

Businesses today are evolving so rapidly that they are resorting to the elasticity of the cloud to provide a platform to build and deploy their highly scalable applications. This means developers now are faced with the challenge of building build applications that are native to the cloud. For this, they need to be aware of the environment, tools, and resources they’re coding against. If you’re a Java developer who wants to build secure, resilient, robust, and scalable applications that are targeted for cloud-based deployment, this is the book for you. It will be your one stop guide to building cloud-native applications in Java Spring that are hosted in On-prem or cloud providers - AWS and Azure The book begins by explaining the driving factors for cloud adoption and shows you how cloud deployment is different from regular application deployment on a standard data centre. You will learn about design patterns specific to applications running in the cloud and find out how you can build a microservice in Java Spring using REST APIs You will then take a deep dive into the lifecycle of building, testing, and deploying applications with maximum automation to reduce the deployment cycle time. Gradually, you will move on to configuring the AWS and Azure platforms and working with their APIs to deploy your application. Finally, you’ll take a look at API design concerns and their best practices. You’ll also learn how to migrate an existing monolithic application into distributed cloud native applications. By the end, you will understand how to build and monitor a scalable, resilient, and robust cloud native application that is always available and fault tolerant.
Table of Contents (20 chapters)
Title Page
Dedication
Packt Upsell
Foreword
Contributors
Preface
Index

Preface

Businesses today are evolving so rapidly that they are resorting the elasticity of the cloud to provide a platform to build and deploy their highly scalable applications. This means that developers now are faced with the challenge of building build applications that are native to the cloud. For this, they need to be aware of the environment, tools, and resources they're coding against. 

The book begins by explaining the driving factors for cloud adoption and shows you how cloud deployment is different from regular application deployment on a standard data centre. You will learn about design patterns specific to applications running in the cloud and find out how you can build a microservice in Java Spring using REST APIs.

You will then take a deep dive into the life cycle of building, testing, and deploying applications with maximum automation to reduce the deployment cycle time. Gradually, you will move on to configuring the AWS and Azure platforms and working with their APIs to deploy your application. Finally, you'll take a look at API design concerns and their best practices. You'll also learn how to migrate an existing monolithic application into distributed cloud-native applications.

By the end, you will understand how to build and monitor a scalable, resilient, and robust cloud-native application that is always available and fault tolerant.

Who this book is for

Java developers who want to build resilient, robust, and scalable applications that are targeted for cloud-based deployment will find this book helpful. Some knowledge of Java, Spring, web programming, and public cloud providers (AWS and Azure) should be sufficient to get you through the book.

What this book covers

Chapter 1Introduction to Cloud-Native, addresses the what and why of cloud-native applications: what are the drivers of moving to cloud application? Why is cloud development and deployment different from regular applications? What is a 12-factor app? 

Chapter 2Writing Your First Cloud-Native Application, introduces the core concepts of using the microservices approach for application design. It then shows a sample bare-bones product service that will be enhanced as the discussion progresses in the book. You will learn how to use Spring Boot for microservice application development and appreciate the microservice principles that are used to build cloud-native applications.

Chapter 3Designing Your Cloud-Native Application, covers some of the high-level architecture considerations in designing cloud-native applications. It includes event-driven architecture, decoupling using choreography, and using domain-driven design (DDD) concepts such as Bounded Contexts. You will learn about the architecture patterns and considerations for developing on the cloud and frontending the applications with consumer-friendly APIs instead of a system-centric service definition.

Chapter 4Extending Your Cloud-Native Application, takes a deep dive into creating an application using various stacks, principles, and supporting components. It covers the patterns while implementing the service. This chapter highlights the differential aspects such as error handling and patterns such as Command Query Response Segregation (CQRS) and caching that have a significant impact on cloud development. 

Chapter 5, Testing Cloud-Native Applications, delves into how to test your microservices and how to write tests in behavior-driven development.

Chapter 6Cloud-Native Application Deployment, delves into the deployment model for the microservice, including how to package your application in a Docker container and setting up the CI/CD pipeline.

Chapter 7Cloud-Native Application Runtime, covers the runtime aspects of the service. We will cover how configuration can be externalized in a configuration server and frontend by Zuul (Edge). We will look at Pivotal Cloud Foundry and deploying our service on PCF Dev. We will also cover container orchestrations.

Chapter 8Platform Deployment – AWS, describes the AWS environment and discusses AWS-specific tools to do cloud development using the concepts (registry, configuration, log aggregation, and async messaging) discussed in earlier chapters.

Chapter 9Platform Deployment – Azure, describes the Azure environment and discusses Azure-specific tools to do cloud development (including Service Fabric and Cloud Functions).

Chapter 10As a Service Integration, discusses the various types of XaaS, including IaaS, PaaS, iPaaS, and DBaaS, and how to expose infrastructure elements as services. In the cloud-native mode, your application might be integrating with social media APIs or PaaS APIs or you can be hosting services that will be used by other applications. This chapter covers how to connect/use other external services or provide such services.

Chapter 11API Design Best Practices, discusses how to design consumer-centric APIs that are granular and functionality oriented. It also discusses the various best practices in API design, such as whether to do orchestration at the API level or in service, how to create freemium versions of API, how to address the channel-specific concerns at the API layer so that the service remains channel agnostic, and the security aspects in API design.

Chapter 12Digital Transformation, covers the impact of cloud development on the existing landscape of an enterprise and how it can achieve the transformation to move toward a digital enterprise.

To get the most out of this book

  1. The book starts with an introduction and then builds on a simple service, step by step, through the chapters. Hence, the readers will benefit by following the flow of the book, unless they are looking for a particular topic.
  2. Downloading the code and running it is always tempting. However, you will benefit more as you type the code out, especially in the initial chapters. The book is written in such a way that the important concepts and code are present in the chapter, thus preventing you from going back to see the source code.
  3. Having said that, do try out the code samples and run them. It makes the principles concrete and easier to grasp. 
  4. I hope that you have invested in a good desktop/laptop, given that you will be running containers and VMs on your machine, which take resources, it is good to have a strong piece of equipment to get going. 
  5. Refer to the documentation links mentioned through the chapters to expand the knowledge on the frameworks and technologies discussed in the book.
  6. The cloud is a technology that changes very rapidly. Hence, this book stresses on concepts and demonstrates them through code. For example, CQRS is important as a concept, so we have shown implementation on MongoDB and Elasticsearch. However, you can try out the pattern on any other set of databases.

Download the example code files

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

You can download the code files by following these steps:

  1. Log in or register at www.packtpub.com.
  2. Select the SUPPORT tab.
  3. Click on Code Downloads & Errata.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

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/Cloud-Native-Applications-in-Java. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: https://www.packtpub.com/sites/default/files/downloads/CloudNativeApplicationsinJava_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The CrudRepository interface comes with a set of default methods to implement the most common operations."

A block of code is set as follows:

-- Adding a few initial products
insert into product(id, name, cat_Id) values (1, 'Apples', 1) 
insert into product(id, name, cat_Id) values (2, 'Oranges', 1) 
insert into product(id, name, cat_Id) values (3, 'Bananas', 1) 
insert into product(id, name, cat_Id) values (4, 'Carrot', 2) 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public class Product implements Serializable {

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

mongoimport --db masterdb --collection product --drop --file D:datamongoscriptsproducts.json 

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Next, we click on the Deployment credentials link on the left-hand side."

Note

Warnings or important notes appear like this.

Note

Tips and tricks appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the book title in the subject of your message. If you have questions about any aspect of this book, please email us at [email protected].

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions. Also, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.