Microservices: Building a Distributed App with Cloud Foundry and Spring
Adopting microservices and a PaaS usually means splitting your data, which leads to dramatic changes in how it is managed, stored, and queried. Watch this video to understand how to modularize data for microservices, how to build scale-out data platforms with Cloud Foundry, and how to implement real-time analytics using Lambda Architecture.
Dividing a monolith application into a set of meaningful services is not easy, especially if your system is already complex. Matt Stine shares some strategies for singling out business capabilities and building a microservices system around them with Spring and CF.
How does it all come together?
In his talk delivered at SpringOne2GX 2014, Matt Stine goes over some strategies for building and managing a distributed microservices architecture. He also shares advice on how to succeed in building microservices and avoid overloading your operations team with unnecessary work. The main three take-aways are that:
- Business capabilities and the data model need to be separated into small meaningful units.
- It is better to use a Platform-as-a-Service, such as Cloud Foundry.
- There are many ways to query data that is spread across several locations—e.g., you can use Lambda architecture.
Splitting a monoliths into microservices
The first one might be the hardest. Dividing data that has always been stored in a single database can be a challenge. However, this step is critical to overall success. Matt Stine offers a plain strategy that can be employed by many businesses. He suggests using contexts to single out business capabilities and underline the data models associated with them. Once you know what activities and data belong to what context, you can build microservices around them. Then you can use a different data store with each microservice to get the features you need in terms of writing/reading speed, transactions, etc.
Using a PaaS to manage microservices
The second point is running and managing all the services. If your system is large, this may be a potential nightmare for your operations team. In addition, how do the people working with your system know how to use each and every datastore type you employ?
Fortunately, there is a kill-two-birds-with-one-stone way to solve both of these issues—a platform, such as Cloud Foundry. A PaaS not only simplifies deployment, monitoring, and management of services, but also creates a level of abstraction between your operators/developers and the underlying technology stack, automating the maintenance and mangement tasks associatied with it. E.g., you can provision a database for your service in minutes.
There are quite some Cloud Foundry-based PaaSes available today. These include public cloud deployments, such as Pivotal Web Services and IBM Bluemix, complete with a selection of pre-installed managed services. On the other side of the spectrum are some options that can be deployed to a private data center—e.g., Pivotal CF and the open source version of Cloud Foundry. Note that if you choose a private deployment, you may need to take care of service provisioning on your own.
Getting business questions answered
Finally, a lot of those who are considering microservices wonder: “How do I get answers to my business questions if all the data and business logic are separated into dozens of small pieces?” or “How do I make queries that span several data stores associated with different microservices?” According to Matt Stine, there are many ways to accomplish this. For instance, you can use Lambda architecture. This approach makes it possible to process data both in real time and in batches, so you can even employ Hadoop and work with big data.
Matt illustrates his points with a live demo of a distributed application for a movie rental service, based on SpringBox Microservices running on Pivotal Cloud Foundry. What’s cool about the app is that it was created in as little as 48 hours. This is a great demonstration of how automation tools, such as CF and the Spring framework, help to save time when building and managing software.
As noted in Matt Stines talk, along with advantages, such as scalability and tighter release cycles, microservices also have a number of downsides, including implicit interfaces, significant operational overhead due to redundancy, and operational complexity. As a result, managing microservices-based systems can become a nightmare, unless you use a PaaS—e.g., Cloud Foundry.
Cloud Foundry takes away a lot of the headache associated with running distributed systems. Here is how it helps to solve the most common issues:
Implicit interfaces. In Cloud Foundry, microservices are deployed as applications and communicate through CF Router. When a service is published, it gets a unique URL in the Cloud Foundry domain. URLs and application routes are created automatically when an application is deployed. Router handles communication between applications in CF in the same way as if they were accessed from outside CF. However, the traffic does not leave the private network. In general, communication between apps in CF is not standardized—there are many different options with various trade-offs.
Significant operational overhead. With Cloud Foundry, application development is simplified considerably. It is just a part of application release life cycle. The PaaS handles development and staging, as well as production applications. There is no need to separate them into different IaaS deployments.
Operational complexity. Cloud Foundry automates scaling and deployment of applications, as well as health monitoring and load balancing. You will not have to create additional scripts to automate monitoring and scaling in your IaaS. In a PaaS, Router serves as a load balancer, so you do not have to add it as a separate component (like when you are using an IaaS).
Lack of DevOps skills. The high level of automation implemented in Cloud Foundry enables developers to concentrate on building and releasing applications. The development, testing, and production release processes are identical in terms of how you deploy. Additionally, the PaaS hides the complexity of the underlying IaaS solution.
You can find more details on how Cloud Foundry helps to address the challenges brought by microservices in our guide.
Want details? Watch the video!
Table of contents
About the speaker