Getting Started With Microservices on Docker and Cloud 66
Get started with microservices with this introduction to features that'll help you stay focused, while avoiding many of the infrastructure tasks of a do-it-yourself approach.
Join the DZone community and get the full member experience.Join For Free
you've decided to embark on the journey to microservices. perhaps you have an existing application written in ruby, node.js, or another programming language. or, perhaps you're planning a brand new application and want to see how microservices might help? it can be daunting to look at all of the work required to get things going: docker infrastructure, service discovery, distributed logging, messaging - the list goes on and on .
this article will help you with getting started with microservices. along the way, you'll get introduced to some of the cloud 66 features that'll help you stay focused as you kickstart the process, while avoiding many of the infrastructure tasks of a do-it-yourself approach.
selecting the 'style' of microservice
the first step to any microservice architecture is mapping out how your microservices will interact. the microservice style you select will drive many of the decisions needed around how to deploy your microservice architecture.
a common approach is to access private microservices via a rest (or similiar) request/response interface from a web tier or public-facing rest-based api. this is sometimes called a layered api or backend for frontend ("bff") approach . public apis are designed to solve external use cases that vary based on the target device, or usage patterns. the public rest apis invoke one or more of the internal microservices as needed.
for microservices needing to respond to events in order to perform background tasks such as data synchronization, messages may be published to a message broker. your microservices publish events to a queue or topic, while one or more message-driven microservices become subscribers to receive the published events and perform the necessary work. we covered this pattern in a recent article " scaling workloads using messaging " .
rest-based microservices are generally easier to construct and manage, but may limit the flexibility and resilience of apis composed of multiple request/response calls to internal rest-based microservices. message-driven microservices are more difficult to implement and troubleshoot, but tend to be more resilient to outages when designed properly.
whatever style you select, it will have an impact on how you containerize your application. let's look at this next.
creating a containerization strategy
putting time aside to consider how you'll containerize your application is very important. for a brand new application, the common choice is to containerize each microservice separately to provide the most flexible deployment options. this has the added advantage of allowing a microservice to be redeployed independently of other services. plus, each microservice can select the programming language and framework most appropriate to get the job done.
for existing applications transitioning to a microservice architecture, things can be more rigid. apis and web applications may be part of the same codebase, making it more difficult to deploy them across separate containers. in this case, containerize your single codebase, then extract new microservices from the single codebase and into separate containers.
cloud 66 offers a flexible approach to docker container management, allowing you to start with a single container or a few small containers. over time, you can expand the number and types of containers that you deploy.
additionally, cloud 66 provides the option of a hosted database-as-a-service, or you can opt to use a managed database on your own, or via a third-party service. if you choose to deploy message-driven microservices, you can also add in rabbitmq as part of your deployment:
with decisions around microservice architecture and containerization strategy out of the way, the next step is to look at the deployment process.
creating docker container images
for cloud 66 to deploy your containers, you'll need to create the docker image with your code, libraries, and other dependencies necessary to make your microservice operate. there are three options available:
- using a public docker image - this is common when there is an off-the-shelf tool you wish to deploy using a public docker image
- bring-your-own image - for teams that already have an internal container image build process, you can publish your own private image and point cloud 66 to it. this gives you full control over the build process, including building images using code repositories or other build processes that depend on internal systems not available over the public internet
- cloud 66 buildgrid - if you wish to get started quickly and with the least overhead, this is the best option. give cloud 66 access to your public or private git repo and the container image will be built for you
when in doubt, start by allowing buildgrid to create container images for your microservices. if you need more control, or need to integrate with internal systems not available publicly, you can build your own images.
selecting a container-ready cloud vendor
when embarking on the microservices journey, you'll find that cloud vendors offer different ways of deploying and managing containers. this can make experimenting with different cloud vendors more difficult, even to the point of accepting a less-than-optimal provider to avoid re-working your deployment process.
cloud 66 removes this risk by allowing you to choose any of their supported cloud vendors to deploy and manage your containers. you can move to a new cloud vendor as desired, or deploy to multiple cloud vendors simultaneously for high availability. deployment, docker image creation, and service discovery will operate in the same way no matter which option you select.
assembling your application stack
one option for deployment is to do it all yourself - from provisioning and configuring servers, to automating the build and image creation process. the problem is, this can be an error prone and time consuming process, as we've detailed before . cloud 66 removes much of this effort, allowing configuration files to define the containers and deployment steps required to deploy each microservice and any public apis, web apps, and other services. plus, you can view logs across all running containers for easier troubleshooting.
moving to a microservices architecture requires some up-front planning to keep the deployment process from becoming fragile. from service design to deployment and monitoring, there are several considerations for deploying a microservices architecture using docker . hopefully this article has helped outline some of these important decisions, while explaining how cloud 66 can help accelerate the deployment process.
Published at DZone with permission of James Higginbotham, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.