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?)
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.