Dependable Microservices via Lattice
Grails 3 makes development of microservices awesome. Docker makes ops for developers of said microservices awesome. However, once we get past “hello, world” and into HOLY TRAFFIC there’s a whole new layer of complexity around scalability and reliability. There have been a handful of tools emerging to target these issues, but in this post I want to introduce Cloud Foundry’s Lattice. If you haven’t heard of Lattice here’s the elevator pitch to save you a click:
What is it?
A project that helps manage a cluster of containers to keep things scalable and reliable so you don’t have to reinvent that wheel during the worst possible time (when you’re app is finally attracting load).
What will it address for these containers?
- Scheduling: balancing containers across available resources as things change
- Routing: configuring routes so started containers can service requests as soon as they are ready (and pull out containers as soon as their health check fails)
- Self Healing: Lattice uses declarative application deployment via Terraform and will automatically right the ship if the system state doesn’t match what you’re expecting
- Status Streaming: Logs from all the containers get aggregated and streamed to one spot for real-time monitoring
- Check out lattice’s documentation for the full feature set including cool capabilities like A/B testing and blue-green deployments
Using Lattice locally with Grails
Let’s go through a simple tutorial of getting a bare Grails 3 app deployed to Docker and clustered with Lattice.
1) Installing and running Lattice
Lattice’s Getting Started docs do a great job explaining how to get everything set up and running. Make sure to follow the instructions all the way through the launching of their sample “lattice-app” to make sure everything is installed correctly.
2) Installing Grails
I would recommend using GVM to install and manage your Grails versions, but it can also be downloaded and installed from the Grails website. For this tutorial you will need Grails 3 or higher. I’m using 3.0.1.
3) Creating the Grails app
4) Setting up a Docker Hub account
You will need to create an account on Docker Hub. We will use it to store the image that will be run in the cluster.
5) Getting the container ready
Much of this is borrowed from the spring-boot-docker guide (hurray for boot-based Grails :-)), so check there for more info. We will start by creating a Dockerfile in the project:
In the Dockerfile, use the following instructions:
Now we need to add the following pieces to build.gradle:
Make sure you replace “group” with your Docker Hub id, or else it will fail while pushing the image. Next we will build the Docker image and push it to Docker Hub (NOTE: if using a Mac, execute this in your boot2docker terminal):
6) Creating the cluster
It should print out a URL to hit the application such as http://grails-lattice-app.192.168.11.11.xip.io.
It may take a while for the image to download so don’t panic if you get a timeout message or the URL gives you an error. Keep checking the status of the application with the command
Once the “Instances” field has the value “1/1” it means the application is deployed and should serve requests. You’re now ready to scale up, crash instances to watch recovery, and all the other fun basic operations from Lattice’s Getting Started docs.
Should I be using Lattice?
Depends on your team size and deployment needs. Lattice is being created for single user/single tenant clusters and is ideal for small teams and simpler use cases. It is a small subset of a full Cloud Foundry Elastic Runtime deployment and serves as its impressive gateway drug. Even if you aren’t planning on using Lattice in production, its ease of use makes deploying and experimenting with a local environment of microservices useful.
One thought on “Dependable Microservices via Lattice”
Hey nice article!
I`m trying lattice lately and I wasn`t able to figure out how to use volumes. I need to setup a distributed file system such as NFS for file sharing between microservices. I`ve notice the /tmp mapping in your Dockerfile, how do you reach that volume?
@Fabio – that’s a good question, I haven’t needed a distributed filesystem for my own uses yet. I used the same volume setup as the article I mentioned for consistency (their reasoning for that setup is noted in the article), though I haven’t been using persistent storage. What have you all tried?
I’m testing a mix of lattice and flocker https://clusterhq.com/ that is an implementation of zfs for Linux and work well with volumes. I didn’t setup the NFS yet.
Another stuff that I’m keeping an eye on it’s http://deis.io/