Martin Joo Profile picture
Computer Science Simplified newsletter: https://t.co/PFJ3lQJ8oR Blog, DevOps, DDD & performance books: https://t.co/yJPUsoqTLh
3 subscribers
Dec 6 15 tweets 4 min read
💡Dealing with statuses and states can be a real headache in larger applications. You can use the state pattern together with transitions and enums.

Some benefits:
- Encapsulation
- SRP
- Small, easy-to-understand classes

🧵Keep Reading Image 1/14 The first step is to create an abstract class or an interface. This is the contract for our states. This is a very simple example.

We have an OrderStatus. The only difference between statuses is that the order can be changed or not: Image
Dec 4 21 tweets 5 min read
💡How to communicate between microservices?

In the microservice world, we often have 10, 20, or even 50+ services. Communication can be pretty complex, so let’s make it easy!

🧵Keep Reading Image 1/20 In the microservice world, we split the app into different, small services and multiple databases.

We obviously need a way to communicate between these services. There are two main ways of communication:
- Sync
- Async, or event-based
Dec 4 10 tweets 3 min read
💰 How to handle money in PHP

There are lots of low-quality projects when it comes to dealing with money, numbers, percentages, transactions, and all that financial stuff.

Here are some tips that you can use:
- Value objects
- moneyphp/money
- Model casts

🧵Keep Reading Image 1/9 Cent values

In order to handle money values in a reliable way we need to store them as cent values. Instead of storing $19.99 as 19.99 in the database, we store it as 1999. This way we'll have no problem with decimal points, rounding, multiplying, or dividing numbers.
Nov 30 9 tweets 3 min read
🔥 Here are some of the most basic monitoring techniques you can start using immediately:
- Spatie laravel-health
- Error tracking
- Syntethic checks

It takes ~30 minutes to set up these.

🧵 Keep Reading Image Health checks with laravel-health

The package can check:
- CPU load
- Disk space utilization
- Database connectivity
- Redis
- And even query speed Image
Nov 28 24 tweets 7 min read
Here are my favorite 22 Laravel packages📦

I would immediately DIE without them!

🧵Keep Reading 1/ laravel-excel

The single best package to handle Excel exports and imports:

- Exporting collections
- Storing files
- Exporting from a query
- Queue jobs
- And more Image
Nov 27 11 tweets 3 min read
🔥 Most applications need to export and import large amounts of data.

It is very easy to:
- Waste lots of memory
- Perform hundreds or thousands of unnecessary DB queries

You can avoid them by learning some pretty simple techniques.

🧵 Keep Reading Image 1/

When it comes to working with larger datasets one of the best you can apply to any problem is chunking. Divide the dataset into smaller chunks and process them. It comes in many different forms.
Mar 12 15 tweets 5 min read
🛠️ How to measure performance in Laravel

There are some pretty simple tools you can start measuring your app's performance with:
- ab
- jmeter
- Inspector
- Telescope

🧵 Keep Reading Image 1/14 Here are some of the most important measures of an API/backend service:
- Throughput: the number of requests the system can handle
- Load time: the amount of time it takes for an HTTP request to respond
- Size: the total size of the HTTP response.
Nov 24, 2023 15 tweets 4 min read
💡How to integrate 3rd parties into your application?

We have to integrate with a ton of 3rd party APIs, and SDKs in every project. You can treat them as mini-applications inside your app.

🧵Keep Reading Image 1/14

Treat your 3rd parties as if they were mini-applications inside your application. They have their own namespaces with their own DTOs service classes and so on. Something like this: Image
Nov 21, 2023 10 tweets 3 min read
💡 If you're running PHP or Laravel apps in production you're probably using nginx and php-fpm.

But do you actually know what these terms mean?
- CGI
- FastCGI
- php-fpm
- How do they connect to nginx?

Let's find out!

🧵 Keep Reading
Image
Image
1/9 CGI

CGI stands for Common Gateway Interface. As the name suggests, it's not a package or library. No, it's an interface, a protocol.

CGI gives us a unified way to run scripts from web servers to generate dynamic content. Image
Sep 20, 2023 11 tweets 4 min read
🔥If you struggle to start with CI/CD pipelines here’s a pretty basic but useful one with:

- phpstan analysis
- phpinsight analysis
- unit tests

🧵Keep Reading
Image
Image
1/10

At the beginning of every GitHub workflow, we need to define what is going to trigger it.

In this case, it’ll run if you push to the main branch or you open a PR to it: Image
Sep 19, 2023 10 tweets 3 min read
💡 If you're running PHP or Laravel apps in production you're probably using nginx and php-fpm.

But do you actually know what these terms mean?
- CGI
- FastCGI
- php-fpm
- How do they connect to nginx?

Let's find out!

🧵 Keep Reading
Image
Image
1/9 CGI

CGI stands for Common Gateway Interface. As the name suggests, it's not a package or library. No, it's an interface, a protocol.

CGI gives us a unified way to run scripts from web servers to generate dynamic content. Image
Sep 11, 2023 18 tweets 6 min read
Here are my favorite 16 Laravel packages📦

I would immediately DIE without them!

🧵Keep Reading 1/17 laravel-excel

The single best package to handle Excel exports and imports:

- Exporting collections
- Storing files
- Exporting from a query
- Queue jobs
- And more Image
Sep 6, 2023 11 tweets 3 min read
🔥If you struggle to start with CI/CD pipelines here’s a pretty basic but useful one with:

- phpstan analysis
- phpinsight analysis
- unit tests

🧵Keep Reading Image 1/10

At the beginning of every GitHub workflow, we need to define what is going to trigger it.

In this case, it’ll run if you push to the main branch or you open a PR to it: Image
Sep 4, 2023 10 tweets 3 min read
💡 If you're running PHP or Laravel apps in production you're probably using nginx and php-fpm.

But do you actually know what these terms mean?
- CGI
- FastCGI
- php-fpm
- How do they connect to nginx?

Let's find out!

🧵 Keep Reading Image 1/9 CGI

CGI stands for Common Gateway Interface. As the name suggests, it's not a package or library. No, it's an interface, a protocol.

CGI gives us a unified way to run scripts from web servers to generate dynamic content. Image
Feb 1, 2023 15 tweets 4 min read
💡How to integrate 3rd parties into your application?

We have to integrate with a ton of 3rd party APIs, and SDKs in every project. You can treat them as mini-applications inside your app.

🧵Keep Reading 1/14

Treat your 3rd parties as if they were mini-applications inside your application. They have their own namespaces with their own DTOs service classes and so on. Something like this:
Jan 25, 2023 14 tweets 4 min read
💡Value Objects Everywhere

I collected some examples of value objects from a financial application I worked on in the past. In a larger, complicated, number-heavy app they really make a big difference!

🧵Keep Reading Image 1/13

In a financial application that deals with publicly traded companies, there are values like these:

- Prices
- Margins
- Ratios
- Market Capitalization
- Numbers in millions

So, instead of using floats and integers, we can create and represent these values as objects.
Jan 19, 2023 25 tweets 7 min read
🔥I just realized I never wrote anything about SOLID principles.

Shame on me… Let’s discuss all of them!

- Single-responsibility principle
- Open-closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle

🧵Keep Reading Image 1/24 Single-responsibility principle

Each class should have only one reason to change.

A great example is data and its representation. Usually, they change for different reasons. Hence it's probably a safe bet to decouple the query layer from the representation layer.
Jan 5, 2023 24 tweets 6 min read
💡There are common mistakes that you can make in Laravel. I collected some of them I see (and make) on a daily basis.

There are three main groups:
- Performance issues
- Deployment issues
- Maintenance issues

🧵Keep Reading Image 1/23 Downloadable PDF

At the end of this thread, you can download a more detailed 40-page ebook (free).
Dec 1, 2022 14 tweets 5 min read
💡There are some common performance issues when working with Laravel. N+1 queries are the most common by far.

They are easy to fix but require some attention.

🧵Keep Reading Image 1/13

No matter what project I worked on in the past, N+1 queries always caused real performance issues.

They usually occur only in production and hard to trigger them while developing.

But first, let's discuss what is exactly an N+1 query problem: Image
Sep 26, 2022 27 tweets 7 min read
💡Here are 25 useful tools for PHP and Laravel developers I use almost daily!

Tools like:
- Medis
- Insomnia
- Hyper
- Notion

🧵Keep Reading 1/26 Insomnia

No, not the sleep disorder. With this Insomnia, you can REST.

It's a really great API client.

insomnia.rest
Sep 14, 2022 13 tweets 4 min read
💡This is a DTO or Data Transfer Object from the Domain-Driven Design world.

It helps you:
- Get rid of random arrays
- Structure your unstructured data
- Type-hints everywhere!

🧵Keep Reading 1/12 Life Without DTO

A DTO is used to store and transfer data inside your app. It’s really just a boring PHP class with some read-only properties.

I guess you have seen 500 lines functions from legacy systems where the only argument is an array called $data, like this: