1.5 KiB
TMDB Retry on Timeout / 5xx
Date: 2026-04-05
Problem
During film import, TMDBGateway makes sequential HTTP calls to TMDB (one searchMovie + one getMovieCredits per new film). Under load, TMDB stops responding and Symfony's HttpClient raises an idle timeout exception, causing the film to be counted as failed.
Goal
Retry TMDB requests automatically on transient failures (idle timeout, 5xx responses) without retrying on legitimate "not found" cases (empty search results).
Solution
Use Symfony's built-in RetryableHttpClient, which wraps any HttpClientInterface and transparently retries on:
- Network/transport errors (including idle timeout)
- HTTP 5xx responses
With exponential backoff: retry 1 → ~1s → retry 2 → ~2s → retry 3 → fail.
If all retries are exhausted, the exception propagates to ImportFilmsBatchMessageHandler which counts the film as failedFilms — unchanged behavior.
Implementation
Only config/services.yaml is modified. No PHP class changes.
services:
app.http_client.tmdb:
class: Symfony\Component\HttpClient\RetryableHttpClient
arguments:
$client: '@http_client'
$maxRetries: 3
App\Gateway\TMDBGateway:
arguments:
$client: '@app.http_client.tmdb'
RetryableHttpClient is part of symfony/http-client which is already a project dependency.
Out of scope
- Rate limiting (not the cause of the current issue)
- Batch/concurrent TMDB requests (TMDB has no batch endpoint)