HTTP callouts in Apex can take a long time to complete, especially when external services are slow or unresponsive. Without an explicit timeout,
Salesforce uses a default timeout of 120 seconds, which is often too long for most integration scenarios.
Long-running HTTP requests consume valuable execution time and can easily cause your code to hit Salesforce’s governor limits. In a single
transaction, you have a maximum of 120 seconds of total execution time. If you make multiple callouts or have other processing logic, a single slow
HTTP request can consume most or all of this time budget.
Additionally, users waiting for a response will experience poor performance when requests take too long to complete. This creates a frustrating
user experience and can make your application appear unresponsive.
By setting an appropriate timeout value, you ensure that HTTP requests fail fast when external services are unresponsive, allowing your code to
handle errors gracefully and maintain good performance characteristics.
What is the potential impact?
Without explicit timeouts, HTTP callouts can consume excessive execution time, leading to governor limit violations and transaction failures. Users
may experience long wait times or timeouts, degrading the overall user experience. In batch processing scenarios, a single slow request can cause
entire batches to fail.