Microservice Architecture using Laravel Lumen

Zeeshan Tariq
2 min readDec 11, 2019

--

What is Microservice Architecture?

It is a method of developing software applications as a suite of independently deployable, small, modular services in which each service runs a unique process and communicates through a well-defined, lightweight mechanism to serve a business goal.

So as definition suggest, it’s a set of independently deployable services. So how we can implement it with Laravel? Please check the diagram below.

Here first layer is a Laravel application, which act as API gateway. All the front ends call API Gateway URL, all the users are first authorized by API gateway. API gateway then calls respective service which is created in Laravel Lumen.

Gateway has sort of service repository which is nothing but singleton class which includes service metadata and hostnames. Using which it can determine which service to call.Here we are using Laravel Passport to authenticate and call service.

Gateway makes asynchronous requests to microservice which is nothing but API call. We don’t block any user request. Gateway can also modify the service response if required and also can cache the request to make response faster.

This microservice will then execute and process the call and will return data in JSON format. Each service is deployed as stand alone instance and have separate host name. The reason for using Lumen for service is it has all the features of Laravel and it’s fast and easy to scale and maintain and it’s ideal for making APIs.

Benefits of mircoservice architecture

There are number of benefits of mircoservice architecture.

Because each service is focused on only a small part they can be more lightweight and much faster performance-wise.

Also since it’s just API calls. It is possible to have different languages for different service. For example there could be notification service made in NodeJs. So it’s not necessary to be only Lumen or Laravel.

Each service can be scaled depending on usage. In short could be a good architecture for large application.

Disadvantages of mircoservice architecture

  1. Mircroservices are more COMPLEX than monolithic applications.
  2. Microservices required CULTURAL changes within than the organization as you tend to use DevOps.
  3. Microservice are more EXPENSIVE in sense that the services need to communicate with eachother which result in high costs associated with network latency.
  4. Posing SECURITY is quite a challenge

Conclusion

While microservices can have the way to substantial improvements to an organizations culture, capabilities, and ability to complete, they are not without risk. Understanding and planning for the advantages and disadvantages of a microservices migration is the key to success. We hope after reading this article you are more aware and better prepared to tackle the challenge.

--

--

Zeeshan Tariq
Zeeshan Tariq

Written by Zeeshan Tariq

Software Architect @ SoftPyramid

Responses (1)