I have heard a lot of times, that PHP does not allow for enterprise ready solutions.
I am PHP Developer and I once believed that's actually true.
Let's imagine team that want to run it's system in stable and solid way.
As an example we will be taking e-commerce business, that allows users to sell and buy products.
Meet Team "Omega"
Team "Omega" have started implementation with "Registration Service", that populate User Model stores it and sends an "Welcome Message' mail with activation link.
Then they have created Product Model, where they store newly create Products, that buyers may choose from.
And at the final they have created an Order Model, that stores information about bought products.
Whenever the order is placed, there are HTTP API calls to two external applications developed by friendly teams. The first one is Billing Platform that invoice the buyer, and the second is Shipping Platform to know where to ship the products.
"Let's make a status, sent / not sent"
The next day after the production release, "Omega" team started to receive complains from the users.
Some of them have no received mail with activation link and could not re-register.
Team figured out that users were registering without second name and because of that email template rendering was failing.
As the transaction was already committed the user was stored in database, however mail was not sent.
Team knew that they have to come with different design to prevent such situation in the future.
They thought about making status for notifications and background process, however they knew that at final it will still be solution keeping database transaction and sending an email within same process. So they considered it as moving the problem to another place.
In that case they decided to introduce Message Broker - RabbitMQ and events.
Whenever registration was done, "Registration Was Finished" event was published to RabbitMQ.
The Mail Sending consumer caught it and sent an mail.
"We need to run synchronization"
After some time, "Omega" team have faced another issue.
Few users have no received the products that they have paid for.
After intensive research they found in old logs, that they indeed stored the order and informed the Billing Platform correctly, however Shipping Platform was down at the moment of placing an order. That caused a situation, when the order was placed, invoice was made, however Shipping Platform was not instructed to send the product.
The first idea to solve this, was to create synchronization process, that will periodically recall the Shipping Platform and Billing Platform to ensure, that they are "synchronized".
They knew however that this kind of solution will be good only for a moment, as when new integrations will appear, they will need to implement it for each of them.
Omega decided that introducing Order Was Placed event is a good start.
If they would create a single consumer for that event, the problem could reappear. As single consumer will pull the message and call both Billing and Shipping.
They came with the solution that they will create two consumers and will publish this event to each of them. So the Billing and Shipping API calls are handled separately.
"Queue is stuck"
Administrators were provided with possibility to provide 10% discount to users.
Whenever discount is provided the email is sent to the user, with promotion code.
New users have once again stopped receiving "Welcome Messages".
The team found out, that due to queue was blocked on sending "Promotion Code" mail.
The consumer tried to handle it and whenever it failed, the message was returned to the queue and consumed again. This blocked all newer notifications from being sent and without "Welcome Message", users could not active their account to log in.
Team knew that this kind of problems may happen and they need to provide a solution, that will allow to sending emails. They have introduced Dead Letter Queue, whenever message failed, it was moved to separate queue for later investigation and thanks to that other mails could be sent.
Long path, but possible...
Omega team had to face many other issues before their system run smoothly and stable.
They shared the knowledge and libraries with other teams as they knew, that going through this process from scratch can take a lot of time.
Building Enterprise ready solutions is possible in PHP. PHP is ready for that, however we us developers need tooling as building own tooling may become second job on it's own.
Ecotone solves those problems for you, so you can focus on business parts of the code.
If you want to build more robust systems with ease, read the tutorial to learn how to apply Ecotone in your existing system https://docs.ecotone.tech/tutorial-php-ddd-cqrs-event-sourcing.