Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gitwithravish's avatar

Microservices using Laravel

Any courses, articles or other resources to see the implementation of microservices in action ?

I have been reading case studies of companies like Uber and how they decided to convert from monolithic architecture to microservice architecture. These studies showed that an application was divided into microservices such as payments, pasanger management, driver management etc.

I could not find a single resource that explains how it gets implemented on development level.

  • How the api endpoints look like ? Is a common api gateway used which connects all small microservice apis ? Or the app uses all different apis directly ?
  • Are these services literally an application deployment in itself ?
  • Some microservices has its own database. If that is so then what about the common data of that app ? For instance how the user_ids are passed in microservice's dbs ?

Please share some resources to implement microservices in using laravel.

0 likes
17 replies
martinbean's avatar

@gitwithravish You wouldn’t use a batteries-included web framework like Laravel for micro services. It defeats the point of micro services if every service is 60MB+.

Monzo, a challenger bank here in the UK, is another company that adopted a micro services approach. But these companies all have one thing in common: a massive engineering team. Micro services just increases development time and complexity, so adopting a micro service architecture doesn’t magically make your application easier to develop or reason about. It in fact does the opposite, as now you have to maintain multiple codebases, orchestrate deploying multiple applications, and so on.

Don’t adopt micro services just because that’s what Uber does. Adopt micro services if you’ve researched them and came to the conclusion that the approach will definitely be better than a “traditional”, “monolith” approach. Because 99% of the time, a monolith will still be the best approach. Even Facebook is still a monolithic codebase and they’ll probably have one of the largest and most complicated codebases in the world.

17 likes
gitwithravish's avatar

Agree to that. Not trying to implement microservices ofcourse.

The reason why I put this post is this - We consulted a couple of solution architect for an enterprise application.

Both the architects asked us to consider nosql over sql saying "nosql is scalable whereas mysql is difficult to scale when app hits a certain threshold. Its very difficult to do horizontal scaling for mysql". and "monolithi app can lead to many problems when app is big which can be solved using microservices. Everyone is using microservice."

Their overshining confidence dragged me here to do some digging. But I feel that people exaggerate new technologies so much that makes the classic approaches look bad. Which is not true.

Thanks @martinbean

5 likes
htdung83's avatar

@martinbean Thanks a lot for your comment. You were absolutely right and I wasted a year to find out.

2 likes
nasrulhazim's avatar

@gitwithravish on sql or nosql, depends on what kind of data you are working with.

p/s: the solution architect should give opinions based on customer needs, not their preference.

underdash's avatar

I think this post is not going to be short, but once and forever I want to clarify micro-services architecture.

A "micro-service" is an application outside the context of your website with which your website communicates. Most of the time, this communication is done by the help of a REST API.

Your client side application can send requests to an API and get the proper response using Javascript's built-in Fetch or a third party library like Axios (Extremely popular in Laravel's community). Moreover, your backend side can send and retrieve information too. For instance, Laravel has a facade called Http, which is used to send different types of requests to any where you wish to.

There are other complicated options for micro-services intercommunication, for example message brokers like Kafka and RabbitMQ but if your are beginning to learn about micro-services you don't need them. They are probably useful for enterprise applications.

To summarize, building a micro-service can be simple as sending an HTTP request, if you are following a valid structure. There are numerous shared characteristics that define a micro-service, like the very fact that each micro-service has a separate database or each of 'em is independently deployable. But at the end of the day the process of creating an application which uses micro-services is NOT complicated.

In conclusion, building micro-services is not as hard as it seems, if you completely understand the underlying dynamics. I'm constantly thinking about creating a follow-along course on Youtube to explain everything is needed to create a micro-service, probably using Laravel, 'cause that is my main choice for building web-based applications. and after starting the course I will post the associated link in this thread.

Hope this helps.

Snapey's avatar

@underdash you said a lot without saying anything I'm afraid. Sounds like the intro to a computer Science assignment.

There are numerous shared characteristics that define a micro-service, like the very fact that each micro-service has a separate database

no, a microservice is probably less likely to have a database, and have the data is needs to operate passed to it through its api. And you failed to mention that microservices give you the flexibility to write them in a language best suited to the type of processing required.

3 likes
underdash's avatar

@Snapey I cannot understand your comment whatsoever. Of course we have multilingual micro-services, but we have micro-services that are based on just one programming language as well.

Different patterns are available and micro-servicing is a concept, not a procedure. The main reason of having micro-services is independence and usually their data is encapsulated as well, which means they have their own database (Database Per Service).

You can use this kind pattern or you can engineer your application in some other way that fits your understanding and personality.

This was exactly I was trying to denote. Focusing just on using different programming languages is NOT what micro-services are for. Any tool (concept) is available to a software engineer to deliver quality software. And these concepts are not exception.

I have tried to break the mold and express this concept in such another simple way that is viable by words. and I'm glad for your comment.

Please let me know if you have any other thoughts about this subject.

3 likes
hollalaykan's avatar

@underdash I agree with you. A micro-service is basically an architecture concept not a procedure. We need to keep breaking things down into smaller chunks for younger engineers rather than use bogus words that makes them look complicated. Great submission @underdash

1 like
gitwithravish's avatar

Below comes from my experience with microservices. Kindly take it as notes.

My Experience with Microservices

  • We have successfully implemented microservices by keeping some characteristics of it. We divided our project into 15 different backend projects including APIs and worker environments.
  • The services that needed database has its own data store. (mysql, mongo and redis)
  • Most of the services are based on laravel PHP, but a couple of those uses python for its AI ML libraries.
  • Every service , its logic, its data is only exposed by one and only one way which is an API gateway in front of each service.
  • This way we could very easily divide developer teams and provided them one or two microservices to work on. They independently work and they do not require to even coordinate back to back with other teams because the standard of the API are maintained regardless of the logical implementations within it.
  • We use message broker service to communicate between microservices so that each service has high availability.

Role of database

  • If a microservice is a worker environment whose job is to perform some tasks / calculations only, then it may not be require for it to have its own data store. You can pass data to it as @snapey suggested
  • Sometimes microservices are require to be very small otherwise it defeats the purpose as @martinbean suggested.
  • A big application can be divided into multiple modules and in that case a microservice may have its own data store. In this case the services are loosely coupled because the database, source code and the infrastructure can be modified, maintained and scaled separately without requiring much knowledge and communication to the other teams and microservices maintainers as far as the API of microservice is keeping its standards as it is.
  • In many cases, having multiple databases might seem very challenging and therefore it could be completely normal and acceptable to have a single database (in some cases). However it introduces coupling for sure, but its just with the database layer. If anything changes in the database and schema design, then every microservice has to make those changes and redeploy.

Monolith vs Microservices

  • Before even diving into microservices, you should first understand the characteristics of it and study a few applications that are built on microservices. Study does not mean you look at an diagram on google which says Order Service, Restaurant Service, Kitchen Service, Accounting Service etc interconnected with adapters and message brokers. We must understand a lot more than that such as what sort of logic is written inside microservice, how they communicate (synchronous / through message broker), what happens if one microservice fails and much much more. You must do good amount of case studies before thinking about monolith vs microservices. If you do not know microservice well, then the default answer is Monolith for you. Because there is nothing worse than building a microservice with half knowledge.

Wrong decision can bite you

I have seen a couple of project that failed because of inaccurate decisions regarding "Monolith vs Microservices".

  1. Monolith was a wrong choice. My first startup company had a typical management who needed a STAR PRODUCT within no time. They forced they saw developers just as "manpower" and therefore the dev team created a big monolith mess. Now, the application worked just fine and we got investment as well and business started off ! The problem arrived while scaling the app. The developers took literally months to launch small feature. And every time a feature was launch, some or the other part of the code was broken. Since the app was so big, new developers took a month to two, just to get a grip on the project. Dividing this application in microservices, just like 2 3 partitions, would have made everyone's life a lot better.
  2. Microservice was a wrong choice. Project from a friend of mine was built with microservice concepts. The project failed because they implemented the architecture in a very wrong way. So wrong that maintaining the architecture become a financial burden and they barely find good teach people who can handle such a mess.

Clarifications

  • There is no mechanical way to design microservices.
  • "Micro' does not necessarily mean a microservice should be small in size. It DEPENDS. There might be projects where the microservice MUST be lightweight and there are projects where the SIZE does not matter, the characteristics that this division of monolith brings matters.
  • People on community platforms speak with different vocabulary and with different contexts, therefore its best that you study the concepts first before opening thread with such vague question on laracast like me.
  • Some people debate that microservice can have a common db as well as shared db. Where as some communities divide both the concept as SOA and Microservices respectively. Some dive deeper and debates SOA can have multiple db as well and this goes on. So never try to learn such big concepts with people's opinions. You need to spend great amount of time learning and experiencing these concepts.

With microservices, what I have learnt is, what matters is the idea of it. The characteristics that it brings and the advantages it brings. Now in order to retain those characteristics, there is no mechanical way. You gotta figure out how you can implement it in the right way.

20 likes
felipeluis's avatar

@gitwithravish Hi, one question, how can I avoid the users access directly to the services? are the services protected using a token? I mean I know that users need to go to the api gateway, but after that? api gateway to services, they use a machine-to-machine authorization?

gitwithravish's avatar

@felipeluis You can have a service solely for authentication which will take care of validating the token. Then you can validate the token on api gateway by calling the authentication service or let the other microservices do this

3 likes
Gadius's avatar

@felipeluis Always remember, as a developer you can do anything!

You usually want to authenticate your endpoints (pc, smarthphones, another server) using some kind of authorization logic, it is usually OAuth2 (Laravel Passport) so i could advice you to check it out.

channaveer's avatar

@gitwithravish Glad, to know you were able to crack the mystery egg around microservices.

Could you please enlighten us on how we could do inter-microservice communication ie. microservice API by calling your other microservice API?

How were you able to join the data from one microservice database to another microservice database?

Armonta's avatar

@gitwithravish Thanks a lot for sharing the result. did you find any implementation of microservices in action with multiple Laravel apps or do you have a public repo for your application?

Please or to participate in this conversation.