Laravel Microservices With Docker

3 min read
1 October, 2024

What are microservices:

In the past, the conventional approach to application development involved creating monolithic applications. However, as we added new features and modules to these applications over time, they inevitably grew larger and more complex. Consequently, maintaining such monolithic applications posed several challenges for us.

A microservices architecture entails constructing an application using self-contained components that function as individual services. These services operate as separate application processes and communicate with one another through well-defined interfaces, utilizing lightweight APIs. Each service is designed to handle specific business capabilities and performs a singular function. Due to their independent nature, each service can be easily updated, deployed, and scaled to accommodate different application functions’ specific requirements and demands.

Why do we use docker for microservices?

When creating microservices, it becomes necessary to select various programming languages, frameworks, and different versions of those frameworks. Consequently, we are required to install different development tools and set up separate environments for each microservice. Fortunately, Docker provides a convenient solution by enabling us to swiftly deploy microservices in their respective development environments, all within Docker containers. This approach streamlines the process of getting microservices up and running, facilitating efficient development, and testing.

How do we create microservices using the Laravel framework with docker?

Let’s begin by developing two microservices utilizing the Laravel framework (version 9) in conjunction with Docker.

I have set up two Git repositories for the Laravel microservice projects, namely laravel-microservice-projectA, and laravel-microservice-projectB. In this setup, when an API request is made to laravel-microservice-projectA, it will communicate with laravel-microservice-projectB. Subsequently, laravel-microservice-projectB will retrieve customer data from the database and send it back to laravel-microservice-projectA. By attempting this process, you will gain a better understanding of how to work with Dockerized Laravel microservices.

Here are the steps to follow:

1. First clone laravel-microservice-projectB and follow the instruction of the git README.md file.

2. After you set up the laravel-microservice-projectB project then you can clone the laravel-microservice-projectA project. Follow the git README.md file instruction and you will be able to up the laravel-microservice-projectA project as well.

3. If everything is done, you can get the customer list of laravel-microservice-projectB by calling laravel-microservice-projectA API. Just try it using the http://api.microservice-a.test:8082/api/v1/customer/list URL In the browser.

In conclusion,

You now have a basic understanding of microservices and have been provided with an example of two interconnected Laravel microservices.

This example serves as a reference to help you grasp the concept of microservices and how they can be implemented using the Laravel framework.

Dilanka Somarathne
Tech Lead
ESSHVA

Related articles

Introduction-to-MuleSoft-ESB
By Esshva · 3 min read
An Introduction to MuleSoft: An Integration Platform for Seamless Connectivity.

MuleSoft is a powerful integration platform offering tools like Design Center, API Manager, and Anypoint...

Read more
By Esshva · 3 min read
Enhancing Pricing Strategy with Algorithmic Insights: A Path to Proactive Price Adjustments

In today’s competitive landscape, online retailers face he daunting task of managing hundreds of thosands...

Read more
My Journey with ESSHVA
By Esshva · 6 min read
My Journey with ESSHVA

Life is a box full of an assortment of chocolates. You never know what you...

Read more
Curious about the people and ideas behind our success?