Using the Cloud to deploy a microservices application
Monolithic applications, built as a single unit, are giving way to newer, modern microservices applications, by breaking down complex architecture into smaller, more manageable ‘blocks’. To achieve this, more and more companies are looking to the cloud to help facilitate this migration. Follow me, as I break down how organizations can scale their microservices easily and more cost-effectively.
The Sock Shop
For this example, we’ll be using the sock shop microservices app. It’s a demo app, highlighting the key features of a modern day e-commerce system. It’s an excellent way to understand and visualize how to migrate a practical, real application.
What exactly is the Sock Shop though? Well, it’s a collection of loosely connected microservices that cater to specific aspects and functionalities such as user authentication, cart and inventory management, order processing, and payment handling. Each microservice is responsible for a specific domain, which can be deployed, developed and scaled independently, allowing for a high degree of modularity and scalability.
The application’s front-end employs this microservices approach as well, because different separate components are responsible for a particular aspect of the user interface, like product catalogue browsing, cart management, and user account management. It’s not (always) all smooth sailing, though. While accurately representing the architectural basics of microservices, the Sock Shop also reveals the challenges posed by such a system. These challenges may include inter-service communication, service discovery, load balancing, fault tolerance, and data (in)consistency across multiple microservices.
Building on that, as the Sock Shop begins to generate (foot?) traffic, there are a few limitations to be overcome in its current state. Scaling the individual microservices gets progressively more challenging as with the growth of the user base. Migrating to the cloud will help in tackling some of these challenges, by leveraging the benefits provided by cloud computing, such as elasticity, scalability and a large suite of management services.
Planning the Migration
Before migrating, we need to make adequate preparation. These include assessing the application to determine what dependencies might be required, choosing a suitable cloud provider based on your requirements, budget, and services they offer, including support for containerization services like Docker and orchestration services like Kubernetes. Other factors to consider are their database offerings, load bearing capabilities and network infrastructure. We’ll be using Amazon Web Services for this particular example.
You should also choose the method you’ll utilize for deploying the app. This could involve deploying and hosting the app in the cloud ‘as-is’, reworking specific components, or updating certain parts of the app to better work with cloud infrastructure.
A roadmap would also be extremely helpful in that it enables you to document the steps you’ll take, and any challenges or milestones you come across. This can be done by breaking down the
Keep an eye on the resources being used for migration, such as time, personnel, and the budget. If you’re working in a team, it might help to assign roles to the various members, like the DevOps engineers (hi, guys), developers and system administrators.
Another key aspect to monitor is the security. Things like access, identity management or security protocols should be hashed out, so as to prevent data breaches.
Lastly, conduct risk assessment to identify any risks that may arise while migrating. Prepare for eventualities like service interruption, performance degradation or data loss, and have an appropriate plan of action. It would not be ideal to lose all your work and data to, say, an accident, and having to start over from scratch. Yeah, not good.
Architecture and Design Considerations
We need to think about how exactly we’ll be deploying the app, like what techniques to employ, so we can take full advantage of the cloud services while maintaining the microservices architecture.
We could try containerisation. Containerisation is just packing together of code with all the libraries, frameworks and other dependencies needed to run it in their own little container. We can use containerisation technologies like Docker to help package the microservices into their own lightweight, isolated containers. This makes deployment consistent and relatively easy across different environments while enabling scalability and simplifying dependency management and versioning.
Next comes orchestration. We can implement an orchestration framework like Kubernetes to help us manage the deployment, scaling, and lifecycle of the microservices. Kubernetes is great because it provides useful features like auto-scaling, service discoveries, and load balancing, all of which are important to effectively managing the microservices in the cloud environment.
Part the Second
Deploying the Application
The first thing we’ll be doing is setting up our environment and installing dependencies. Run the following commands to install them:
curl -sSL https://get.docker.com/ | sh
apt-get install -yq jq python-pip curl unzip build-essential python-dev
curl -o /tmp/terraform.zip https://releases.hashicorp.com/terraform/0.7.11/terraform_0.7.11_linux_amd64.zip
Now clone the repository and go into it:
git clone https://github.com/microservices-demo/microservices-demo
cd microservices-demo
Next, we’ll set up WeaveScope on your local machine:
sudo curl -L git.io/scope -o /usr/local/bin/scope
sudo chmod a+x /usr/local/bin/scope
scope launch
Use the following command to provision the infrastructure we’ll need with Docker:
docker-compose -f deploy/docker-compose/docker-compose.yml up -d
Once the app is deployed, you should be able to reach Kibana on http://localhost:5601.
Then we can use the included load test to simulate user traffic with:
docker run --net=host weaveworksdemos/load-test -h $frontend-ip[:$port] -r 100 -c 2
You can now destroy the infrastructure (you don’t want a hefty cloud provider bill, trust me). Run the following command to take it all down:
docker-compose -f deploy/docker-compose/docker-compose.yml down
That’s about it, the Sock Shop deployed with Docker and WeaveScope. We proudly raise our socks to the future, embracing the challenges and opportunities that lie ahead with optimism, determination, and the belief that the sock shop will continue to thrive and leave a lasting impression on every foot it touches for years to come.