I’m building an Elixir Umbrella project to be a web service for Alexa Skills (here is the apps folder on GitHub.) When I speak a request to Alexa, Alexa sends a JSON request to my Phoenix app. My Phoenix app calls a function in my Alexa Skills app to process the request. I have an app to transform the JSON to Elixir structs and generate the response struct. Then I built another app in my umbrella that sends a HTTP request to get the latest train status for the nearest metro stop. The goal is to send that info back to Alexa formatted in Alexa response JSON format. I have it working, but I’m wondering if there is a more idiomatic way to structure it from an OTP perspective.
I built the metro app “wmata” using the Metex app from The Little Elixir and OTP Guidebook as a template. The Metex app makes an http request to a weather API and stores the results. To store the results it uses a GenServer. I just updated it to send the request to metro API.
For my app, I’m not interested in storing the results. I just want to format the JSON and send it back to my Alexa. Since I don’t need to store the results, I don’t think I need a GenServer. Furthermore, as I’ve read up on GenServers, it could potentially create a bottleneck in my overall application (not that I expect it to get that big, but I want to create my app using a proper design.) Also, I don’t know that a GenServer provides me a benefit in my case.
Here are a couple of posts I found on the topic.
Question Regarding GenServer Use
Task, GenServer, or GenStage
Should I simply remove the GenServer and call the function from the process the Phoenix app creates? Or do people set up something like a supervised Task to handle external API http requests? I’m using HTTPoison, so I’m guessing any supervision/error handling is done within HTTPoison or Hackney. Is a supervisor necessary in my case?