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

click's avatar
Level 35

How to use microservices in a webshop?

Hi there,

I am investigating the options on how to make my application scale better in the future and separate responsibilities of parts of the code. And quite some time ago I already read some things about microservices but I never fully understood on how to implement this in my own projects.

Let's say I have webshop. The main application is build in Laravel and currently all logic and data is stored there like inventory, orders, users, clients, invoices, product information etc.

How would you transform this application in an application that makes use of multiple 'microservices' (SOA?) with the use of Lumen for example.

Would you create a microservice that is only responsible for accepting new orders? And one microservice that is only responsible for creating invoices and sending them to the ERP? And one for updating product information from external parties?

How does this work with the data of each microservice? Do you have one database server that is used by all of the microservices? This defeats the idea of separation of concern. Should every microservice has it's own database?

I think I understand the principle of microservices but I am a little bit confused on how to implement this in a real life project.

Does anyone has an example project where multiple microservices are being used. Or maybe an article of a real life implementation?

0 likes
8 replies
click's avatar
Level 35

I already read that article and it does not help me with my questions. In their webshop example the have a cart server and a product server. And both of the servers use separate storages. But you can't fill a shopping cart without a reference to a product. And the cart should probably know something about the stock.

How would this be solved?

1 like
topvillas's avatar

Don't count me as some sort of microservice guru but this is my take.

You should try and stop thinking about Eloquent relationships. They're fantastic for monoliths but aren't really much use in a microservice architecture.

Think in terms of GUIDs. A cart would contain GUID references to products that are fetched separately as a collection from the product service.

The same for stock. When you display a product, check with the stock service for availability. Then send a collection of GUIDs to the stock service on checkout to adjust stock levels.

click's avatar
Level 35

Thank you for your reply.

I've read the last days quite some articles and found a few that could be interesting for others reading this ticket. Data management can be quite a challenge depending on your requirements. With a normal database you can commit all your sql queries in one transaction so you are sure all of them will be successful or all of them fail. With using separate microservices this is a little bit more complex.

I am still in the process of reading and understanding how I can implement this in my project.

Web Confection's avatar

I work in a microservice environment and a lot of it is totally counter-intuitive. Regarding your question;

"Do you have one database server that is used by all of the microservices? This defeats the idea of separation of concern. Should every microservice has it's own database?"

You are quite correct, a microservice should never-ever share its storage. Each must have it's own DB. One of the few cardinal rules.

Try looking at serverless.com. I have published an example microservice template at https://github.com/jacksoncharles/serverless-qa-template-api

Happy to try and answer any specific questions but there are very few definitive answers.

martinbean's avatar

There was a good maxim doing the round a while ago but I can’t remember who said it.

If you’re considering moving to a micro-services architecture, paraphrasing:

If you have more micro-services than developers, you’re doing it wrong.

Micro-services may make sense if you’re a company the size of Amazon, and have lots of engineering teams distributed across the globe (it’s in fact what AWS was borne from), but if you’re just a lone developer making a web shop, then micro-services are probably not for you.

2 likes
Web Confection's avatar

@martinbean I have sympathy with your later comments but regarding the maxim

"If you have more micro-services than developers, you’re doing it wrong."

Twaddle :) Staff numbers are irrelevant.

Please or to participate in this conversation.