JVM Advent

The JVM Programming Advent Calendar

Components of Cloud Native Java

WHAT IS CLOUD NATIVE JAVA 

Cloud native is a software approach to building, deploying and managing modern applications in cloud computing environments. 

It allows companies to build highly scalable and resilient applications that can easily be enhanced to meet customer needs without breaking existing functionality. The cloud native approach involves immutable infrastructures which enables the servers that are hosting the applications to remain unchanged after deployment, microservices that allow the product to be broken apart into smaller applications that serve only one purpose, containers which are used to store services and allow for the application to run independent of OS and hardware, and many other tools that are making the cloud native paradigm a favorable choice of many modern applications.

Microservices

Microservices are small autonomous services that work together. They are the foundation that is essential to building cloud native applications. 

 advantages:
  • Time to market: The smaller the code base is, the easier it is to develop and release into production.
  • Productivity: When new developers join the team they can more easily set up their local development environment, as well as become productive faster.
  • Extensibility: When we need new functionality we can just add more microservices.
  • Replaceability: When we need to change a part of the application we can modify and redeploy only the respective microservice and not the whole application.
  • Scalability: Microservices can be independently scaled. If a certain service is highly used or is essential to the application, it is a great candidate for being scaled – either horizontally (by having multiple instances of it), or vertically (by adding more CPU and RAM to the machine on which it is deployed).
Microservice resilience with Spring Cloud

Spring Cloud is a project built on top of Spring Boot, which is designed to aid the development of distributed systems such as microservices. The Spring Cloud suite of projects contains many of the services you need to make your Java applications run in the cloud. These services include: API Gateway, Cloud Configuration, Circuit Breakers, Service Discovery, Tracing, Testing, Distributed messaging, Leadership election and cluster state, Global locks, Load balancing, Service-to-service calls, Routing. Click here for more information about Spring Cloud.

Simple Spring Cloud Architecture example

Containers

Containers and the most widely adopted containerization solution, Docker, are another fundamental part of most modern cloud based Java applications.

They are executable units of software in which application code, along with their libraries and dependencies are packaged together. 

The popularity of containers among IT professionals is growing.

According to a survey conducted by SlashData for Cloud Native Computing Foundation among around 4000 developers from all over the world, 62% of the respondents in Q1 2020 have been using containers and in Q1 2021 – 73%.

If we take a closer look at the containerization technology we would find some similarities from a conceptual point of view between it and the JVM(Java Virtual Machine). Just like JVM, Docker enables CPU and RAM usage limitation and monitoring. Both technologies achieve portability by isolating the application from its runtime environment. What Docker does additionally is that it packages the application, JVM and all other dependencies together. This ensures that the container will always include compatible versions of the JVM and the application. 

Containers also improve on the idea of virtual machines(VMs), where the applications are run on a software emulation of a physical machine.

However, VMs have one big disadvantage – each application should have its own guest operating system – this leads to poor horizontal scaling.

advantages:
  • Lightweight: Containers share the machine OS kernel, eliminating the need for a separate full OS instance per application. Their smaller size means they can spin up quickly and better support cloud-native applications that scale horizontally.
  • Portable and platform independent: Containers are packing all their dependencies with them, meaning that software can be written once and then run on any hardware and OS without any additional reconfiguration.
  • Supports modern development and architecture: Due to their deployment portability across platforms and their small size, containers are an ideal fit for modern development and application approaches — DevOps, serverless, and microservices as they are built on regular code deployments in small increments.
  • Improves utilization: Thanks to their improved design and smaller size compared to VMs, provide more benefits in addition to improving CPU and memory utilization of physical machines. They also enable microservice architectures that can be deployed and scaled more granularly.
disadvantages:
  • Complexity: Containers add to the complexity of a project and their impact should be considered when the architecture is designed.
  • Insufficient expertise in container development and management: Finding talent familiar enough with the technology is another common difficulty among IT companies.
  • Redesign: This is an especially important drawback for applications that were not developed as cloud native in the first place (like monolith for example). The architecture redesign and code refactoring introduce a lot of risk that should be carefully calculated.

With all that said, containers will still grow in popularity in the near future and will be the best choice for modern Java applications. As for legacy solutions, the pros and cons will have to be weighed for each different case.

CI/CD

CI/CD stands for continuous integration, continuous delivery and continuous deployment. This is a methodology for frequently developing code changes more frequently and reliably. Also it is a best practice in agile methodology.

Continuous integration

Continuous integration focuses on smaller commits and smaller code changes to integrate. A developer commits code at regular intervals, at minimum once a day. The developer pulls code from the code repository to ensure the code on the local host is merged before pushing to the build server. At this stage the build server runs the various tests and either accepts or rejects the code commit.

Continuous Delivery and Deployment

Continuous delivery (CD) is a software development practice where code changes are automatically built, tested, and prepared for production release. It expands on continuous integration by deploying all code changes to a testing environment, a production environment, or both after the build stage has been completed. Continuous delivery can be fully automated with a workflow process or partially automated with manual steps at critical points. When continuous delivery is properly implemented, developers always have a deployment-ready build artifact that has passed through a standardized test process. With continuous deployment, revisions are deployed to a production environment automatically without explicit approval from a developer, making the entire software release process automated. This, in turn, allows for a continuous customer feedback loop early in the product life cycle.

Common CI/CD tools in Java environment

All CI/CD tools do the same work: They run mundane, repetitive tasks to safely ship iterative code updates to end users. Their functionality covers:

  • build automation, where build means turning source code into a deployable version,
  • test automation
  • deploy automation

Due to the dynamically evolving cloud-native space in Java the most used CI tools often vary. Among the most popular  are Jenkins, Buddy, TeamCity, Travis CI. These tools support a wide specter of platforms and features due to this fact it is hard to determine which one would suit you best. For reference, check out the link  where the Java community provides feedback on the pros and cons of the different software.

A complete CI/CD workflow typically looks like this:
CI/CD in JAVA Spring Application

Sample project structure:

  • Gradle/Maven are used for dependency management, to build and run individual microservices.
  • Docker – you can check in 3. For more information on containers
  • Jenkins – essentially defines the automation pipeline with various stages such as build, test, dockerize, run docker container etc. It is used by Jenkins to trigger a job as per the defined pipeline.
Is Java ready for Cloud native?

Java as a whole already has the necessary tools, and enhancements are being made to both the language and the tools that are supporting it, to be part of the cloud native community.

Even though, approaching 28 years of age the language still has a broad community of developers, frameworks and tools that are enabling it to remain in the fast-paced modern industry. Tool providers such as AWS, Docker, Kubernetes and many others, are passionate to integrate Java into their systems as it is a programming language that is still the leading force of a lot of applications and would be of financial benefit to them.

What is probably the biggest setback in Java being cloud native is that the majority of developers are not familiar with all the new tools and technologies that are being used to develop a cloud native application. Small to mid-sized companies do not have the resources to invest in the teaching of those developers which leaves them out of the cloud native space.

However, more and more companies are adopting the cloud native approach and are investing in the development of new skills through internal and external academies for their software engineers, which will inevitably put Java forward in the cloud native space.

 

Next Post

Previous Post

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2023 JVM Advent | Powered by steinhauer.software Logosteinhauer.software

Theme by Anders Norén

%d bloggers like this: