how to make oracle UTL_HTTP.request asynchronous?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Oracle's `UTL_HTTP` package is used to make HTTP requests from within the Oracle Database. It provides functionalities to interact with web services directly using SQL and PL/SQL. However, by nature, the `UTL_HTTP.REQUEST()` function is synchronous, meaning it waits for the HTTP transaction to complete before moving on with the rest of the code. For use cases that require responsiveness or when interfacing with slow HTTP services, making these requests asynchronous can be beneficial. In this article, we’ll delve into approaches for achieving asynchronicity in `UTL_HTTP`.
Understanding Synchronous vs Asynchronous
Synchronous Requests
In a synchronous HTTP call using `UTL_HTTP`, the client (in this case, the PL/SQL procedure) must wait for the response from the server before proceeding. This can lead to inefficiencies if the server is slow to respond or if multiple requests are being made sequentially.
Asynchronous Requests
In an asynchronous processing pattern, the client sends a request to the server and continues its execution. When the response is ready, the server notifies the client or the client periodically checks for a response. This can improve system performance and user experience, especially in a database environment where resources are shared.
Making UTL_HTTP Asynchronous
Oracle's PL/SQL does not natively support asynchronous programming patterns like other programming languages (e.g., JavaScript's Promises or Python's `async`/`await`). However, you can use some workarounds to mimic asynchronous behavior:
- Database Job Scheduler: The `DBMS_SCHEDULER` package can be utilized to run PL/SQL blocks as background jobs. This is perhaps the most straightforward approach.
- Apex Web Service APIs: If you are using Oracle APEX, you can leverage APEX Web Service APIs, which are better suited for managing HTTP requests, especially when dealing with delays or timeouts.
- Advanced Queuing (AQ): Oracle's Advanced Queuing allows for decoupled processing of messages. You can enqueue HTTP requests and process them asynchronously.
- Custom Background PL/SQL Process: Implement a custom PL/SQL loop that periodically checks for tasks (e.g., HTTP requests) and executes them.
Using Database Job Scheduler
Here is an example of how to leverage the DBMS_SCHEDULER:
Related reading
- How to make primary key as autoincrement for Room Persistence lib
- How to make Sequelize use singular table names
- How to make Spring server to start even if database is down?
- How to manually create a mdf file for localdb to use?
- How to make RabbitMQ API calls with vhost /?
- How to make reactive webclient follow 3XX-redirects?
- How to make parallel calls in Erlang and wait for all of the results?
- how to make synchronous call to indexeddb method from javascript

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.