Pooling third-party API for each app user in the background - ideas?

Hello, Elixir community!

Imagine a web app with authentication. When users log in, they can create a new “item”. Items are stored in the database. For each item, my app needs to constantly call a third-party API and check if something is changed in response. (no limitations on how often API can be called, but likely there is a limit of 3 requests per second)

How would you implement that? Thanks for any ideas (I’m new to Elixir, but looks like it has something to offer for this specific case, things like GenServer?)

1 Like

Hey Ostap! I recognize your name from around the maker community, big greetings and welcome to Elixir :slight_smile:

For this, I’d pull a very basic GenServer. I’m actually doing this in a current project: fetching data from Paddle’s API to diff any changes.

Here’s a working example. This example is the one I’m using to do what I mentioned. Not too hard to understand and works great!

2 Likes

Welcome to the community, Ostap! You could use background jobs for that, e.g. Oban: GitHub - sorentwo/oban: 💎 Robust job processing in Elixir, backed by modern PostgreSQL by enqueing a new job each time you process the API request and adding some delay to handle throttling. This would be not very efficient, since it would hit the DB frequently (depending on the number of users), but the business logic would be very simple.

2 Likes