Microservices Architectures - Non Functional Requirements - Performance


Image Image


In this article, we explore the important non functional requirement called performance.

What you will learn

  • What Is Performance?
  • Why is Performance important?
  • What are the best practices in building performant systems?

Free Courses - Learn in 10 Steps

Non Functional Requirements and Microservices

This is the part of a series of articles on Non Functional Requirements:

What Is Performance?

When we type in a web page URL in a browser, performance from a users perspective is the time it takes for the page to load.

Performance is essentially a measure of how much time a system takes to respond to a user request.

Consider the following simple microservices architecture:

image info

There are three microservices in here, that communicate with several kinds of common components and other infrastructure. How would you go about improving the performance of a system such as this one?

Let’s look at different aspects of this goal.

Improve The Code

The first step would be to improve the performance of code written for each of these microservices. If for instance Microservice1 is written in Java, then make sure you follow the applicable Java best practices for its code, such as:

  • Making best possible use of Java collections
  • Not creating too many objects
  • Using the right efficient data structures and algorithms, in your business logic
  • Make sure that the microservices are profiles and performance tunes to the maximum possible extent

Fine-Tune Your Databases

If your application accesses a database in order to store and retrieve data, then such access needs to be efficient. For example, your microservice could be talking to a data service in order to manage its data, much like the following:

image info

For that, you need to ensure that the databases used are fine-tuned to the kind of queries used by the microservices. This would include things such as:

  • Proper use of indexes

Cache Your Data

Particularly in web applications, quite a few aspects of data handled by it can be cached.

If caching were not used, a lot of static content, including HTML/CSS/JavaScript would need to be transferred repeatedly between the server and the browsers.

Similarly, a microservice need not always fetch data from the data store. It could have a cache built in at the business logic, where it stores recently or frequently accessed data.

Another aspect to look at is the kind of caching mechanisms that can be used. The caching model could be a database-specific cache such as at the JPA level, or a distributed cache.

If you use a distributed cache, data accessed by different instances of a microservice could be cached centrally.

Build Redundancy

The next option available to improving application performance, is to build redundancy.

In our example, instead of having one instance each of Microservice1, Microservice2 and Microservice3, have say 10, 5 and 3 instances. The number of microservice instances created depends on the expected load on each such microservice. This would allow the application to handle a larger volume of requests within lesser time, and lighter load on the server in general.

You could also build redundancy by having multiple instances of each type of common infrastructure.

Improve System Capacity

Another option is to improve the configuration of each of the servers. This could involve arranging for better CPU processing power, and augmenting the amount of available physical memory.

Ensure Modular Design

In our microservices architecture example, you have noticed that we have built the system in a modular way. We have designed different types of components for different responsibilities, as well as organized infrastructure code into different modules.

At a design level, one of the ways to improve the performance of a large monolith application would be to make it more modular. For example, splitting it up into components would enable us to deploy them onto different servers.

Best Practices For Performance Improvement

Until now, we have looked at different options that are available to improve the performance of an application. Let’s now look at a few best practices for improving an application’s performance.

Have Clear Guidelines

You must have clear performance guidelines from the start of a project. Do not wait until the end of the project to outline these.

The requirements should clearly list out the system parameters, such as the number of system users, the peak load, the expected response time, among others.

Test Performance Early

You need to test your application’s performance early, and not just leave it to the end. Ideally, performance tests need to be part of your definition of done.

Profile Your Code

Make sure you profile your code at regular intervals of time, to identify places of improvement. After identifying them , effort should be put in to fine-tune the application to address this feedback.

Ensure Visibility

Whenever you find a performance problem with your application, you need to identify the root cause. Also, when you need to give a fix for this, the solution should be one that gives the best possible improvement.

Nailing down the root cause of a problem is only possible if you have great visibility of what is going on.

You would need clear visibility into what’s happening with the request in the back ground

  • What microservices are involved? How much time is spent in each of them?
  • What infrastructure components are involved? How much time is spent in each of them?

The more visibility you have into an application, the easier it is to identify performance bottlenecks.

Do check out our video on this:

image info

Summary

In this video, we say that performance is a measure of how much time a system takes to respond to a user request. We saw that there are a number of aspects to how to improve application performance.

The first aspect refers to improving the code to adhere to the language, framework best practices. Then, you could work on fine-tuning the performance to databases to which the system has access to. A third option would be to introduce caching as a practice to store recently, or frequently accessed data. Introducing redundancy improves performance by distributing the load on a server, among different nodes.

We then looked at general best practices for performance improvement. These include having clear performance guidelines early on, testing regularly for performance, profiling code frequently, and improving traceability.

Related Posts

Docker Tutorial for Beginners - with Java and Spring Boot

Learn about Docker - What is Docker? Why Is Docker Popular? How to create Docker Image for a Java Spring Boot App?

Devops Tutorial | DevOps with Docker, Kubernetes and Azure DevOps

What is DevOps? How is it different from Agile? What are the popular DevOps Tools? What is the role of Docker, Kubernetes and Azure DevOps in DevOps. Let's get started with a simple usecase.

Deploy Java Spring Boot Applications to AWS, Azure, GCP with Docker and Kubernetes

In this article, we focus our attention on the cloud. How to learn the cloud and deploy Java Spring Boot Applications to AWS, Azure, GCP with Docker and Kubernetes?

Spring Boot Tutorials for Beginners

At in28Minutes, we are creating a number of tutorials with videos, articles & courses on Spring Boot for Beginners and Experienced Developers. This resources will help you learn and gain expertise at Spring Boot.

Microservices with Spring Boot and Java - Part 1 - Getting Started

Let's learn the basics of microservices and microservices architectures. We will also start looking at a basic implementation of a microservice with Spring Boot. We will create a couple of microservices and get them to talk to each other using Eureka Naming Server and Ribbon for Client Side Load Balancing. In part 1 of this series, lets get introduced to the concept of microservices and understand how to create great microservices with Spring Boot and Spring Cloud.

20+ Spring Boot Projects with Code Examples

At in28Minutes, we have created more than 20 projects with code examples on Github. We have 50+ articles explaining these projects. These code examples will you learn and gain expertise at Spring Boot.

REST API Best Practices - With Design Examples from Java and Spring Web Services

Designing Great REST API is important to have great microservices. How do you design your REST API? What are the best practices?

Index - 500+ Videos

At in28Minutes, we are creating a number of tutorials with videos, articles & courses on Spring Boot for Beginners and Experienced Developers. Here's a list of video tutorials and courses for you

Creating Spring Boot and React Java Full Stack Application with Maven

This guide helps you create a Java full stack application with all the CRUD (Create, Read, Update and Delete) features using React as Frontend framework and Spring Boot as the backend REST API. We use Maven as the build tool.

Creating a SOAP Web Service with Spring Boot Starter Web Services

Let's learn how to create a SOAP Web Service with Spring Boot Starter Web Services. We will take a Contract First approach by definining an XSD and exposing a WSDL from it.

FREE COURSES



in28Minutes Best Selling Udemy Courses

Image Image Image Image Image Image Image Image Image

450,000 Learners are pursuing our 31 amazing courses and 6 Learning Paths. Start Now!

Join 450,000 Learners and 30+ Amazing Courses

LEARN DEVOPS - 200+ VIDEOS - Master DevOps with Docker, Kubernetes and Azure DevOps


350,000 Learners are learning everyday with our Best Selling Courses : Spring Boot Microservices, Spring, Spring Boot, Web Services, Hibernate, Full Stack React, Full Stack Angular, Python, Spring Interview Guide, Java Interview, Java Functional Programming, AWS, Docker, Kubernetes, PCF, AWS Fargate and Azure


85,000 Subscribers are learning from our Free Videos on YouTube : JSP Servlets, Spring, Spring Boot, Spring MVC, Hibernate, Eclipse, Maven, JUnit, Mockito, Full Stack - React, Full Stack - Angular, Docker, Kubernetes, AWS, AWS Fargate, PCF and Azure


Here are the recommend articles to read next : Spring Interview Questions, Spring Boot Interview Questions, Microservices, Hibernate, Spring Security, REST API with Spring Boot, Full Stack with React, SOAP Web Services, Exception Handling, Embedded Servers, Spring Data Rest, Spring vs Spring MVC vs Spring Boot, Building Web Application and Spring Data JPA.

You can checkout all our 100+ articles here - All Articles.


Do not know where to start your learning journey? Check out our amazing learning paths:
Learning Path 01 - Spring and Spring Boot Web Applications and API Developer,
Learning Path 02 - Full Stack Developer with Spring Boot, React & Angular,
Learning Path 03 - Cloud Microservices Developer with Docker and Kubernetes,
Learning Path 04 - Learn Cloud with Spring Boot, AWS, Azure and PCF and
Learning Path 05 - Learn AWS with Microservices, Docker and Kubernetes


Subscribe