'django 3rd party API Event Loop?

I'm quite new to back-end development so please forgive my ignorance.

I need to connect my Django backend to a 3rd party API to fetch live location data from GPS trackers. This needs to be done server side as it triggers other events, so it can't just be run in the browser.

What's the best way to go about doing this please? So far I have thought of something like an event loop which calls the API every 60 seconds, but can I run this on a separate thread for example? Is that even the best thing to do?

Is it possible to do something like a websocket form my backend to the 3rd party? What's the best way of keeping this data updated?

Finally, how does a solution like this scale, what if I had 5,000 vehicle trackers which all needed updating?

Any advice would be greatly appreciated.

Thank you.



Solution 1:[1]

you might create an empty webpage which triggers your backend logic,

and configure cronjob which would send get request on this page every 60 seconds,

it also will be started on separate thread by deafult.

you might scale it for example you have 5000 vehicles, just split this backend logic on two different functions(each 2500 vhicles) (which would be triggered by two different get requests), and they would work independant, on separate threads)

or you can use asyncio to split your logic inside one function, and still start it asynchronously and separatly

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 oruchkin