V
V
vitya_brodov2022-03-08 16:05:35
Java
vitya_brodov, 2022-03-08 16:05:35

How to design API to avoid 504 Gate away error?

Hello, I have an API written in Java Spring boot that takes an .XLSX file as input and parses the data inside the loop into a list of objects.
With each iteration of the loop, using WebClient, it knocks with a parameter on a third-party API from the database and receives some data back. Then it writes all the parsed data to a file and issues it back.
The problem is that, due to large calls to a third-party API, the program takes too long (5-7 minutes) when I run it on prod, I get 504 Gate away.
Question: How can you optimize or intelligently design to avoid the above problem?
There are thoughts to use asynchrony or multithreading, but I'm not sure that this is a solution to the problem.
Please share your wisdom.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-03-08
@vitya_brodov

If it is the external API that slows you down and this API will normally withstand a large number of simultaneous requests, then asynchrony will more than help. I recommend looking at Webflux and / or Kotlin coroutines.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question