Mar 29, 2026
Coding

How I Sped Up Hundreds of API Requests in Laravel

Recently, I ran into a problem that looked simple at first, but quickly turned into a performance bottleneck.

I needed to fetch a directory of cities and branches from a third-party delivery service for an ecommerce checkout page. Since the store supports multiple languages, the same dataset had to be fetched in different languages.

That alone wasn’t the problem.

The real issue was the API.

When the API Works Against You

The delivery service API was extremely limited. There was no way to fetch all the data in a single request. Instead, I had to request each city separately, and for each city, repeat the process for every supported language.

What seemed like a straightforward integration quickly turned into hundreds of HTTP requests.

At first, I implemented it the obvious way: a loop that sends requests one by one. It worked, but the execution time became painful. Updating the data took several minutes, which was far from acceptable for something that should feel routine.

At that point, the problem was no longer about correctness. It was about efficiency.

The Shift From Sequential to Parallel

The key realization was simple: the requests were independent. There was no need to wait for one to finish before starting the next.

That’s where Laravel provides a useful tool: Http::pool().

This method allows you to send multiple HTTP requests in parallel instead of sequentially. Instead of waiting for each request to complete, Laravel can dispatch many of them at the same time and collect the results together.

In my case, I grouped requests by language and executed them concurrently. That small change dramatically reduced the total execution time.

What previously took minutes dropped to a much more reasonable duration.

A Simple Example

Instead of doing something like this:

foreach ($cities as $city) {
foreach ($languages as $lang) {
$response = Http::get("api/branches?city={$city}&lang={$lang}");
// process response
}
}

You can use a pool:

$responses = Http::pool(function ($pool) use ($cities, $languages) {
$requests = []; foreach ($languages as $lang) {
foreach ($cities as $city) {
$requests[] = $pool->get("api/branches?city={$city}&lang={$lang}");
}
} return $requests;
});

Now the requests are sent in parallel instead of one by one.

The Trade-Off You Shouldn’t Ignore

Parallelization is powerful, but it comes with responsibility.

Most APIs enforce rate limits. If you send too many requests at once, you risk being throttled or even temporarily blocked. This is especially important when dealing with third-party services that are not designed for high concurrency.

In practice, this means you should control how many requests you send at the same time, either by batching them or adding delays when necessary.

Performance improvements should not come at the cost of reliability.

What This Changed for Me

This experience reinforced something important: performance problems are often not about optimizing code, but about changing how the system behaves.

The logic didn’t change.
The data didn’t change.
Only the execution strategy changed.

And that made all the difference.

A Better Way to Think About It

Whenever you’re working with external APIs and large datasets, it’s worth asking a simple question:

Do these requests really need to be sequential?

If the answer is no, then parallelization is often the easiest win.

Laravel’s Http::pool() makes this approach accessible without adding much complexity. Used carefully, it can turn a slow process into a fast one with minimal changes to your code.

Thanks for reading!