Does anybody have a OTP/Genserver/Flow web app project?

Hello all,

I’ve been trying to learn and study how OTP/Genserver/Flow works within the context of a web application and am at the point where I grasp the concepts but think it would really solidify the lessons if I “look under the hood” in a real web app project.

Does anybody know of any projects?

I was going to post this in the projects section but couldn’t find anything there.

Thanks in advance!

There are

ElixirConf 2016 “Selling Food With Elixir by Chris Bell” talk is also quite nice

1 Like

Here is my authentication library. It may help to look at it because its quite small for the most part. Uses genserver and sub supervisor to manage tokens(the actual logic probably needs cleaned up though).

1 Like

Do you keep the tokens in a single genserver?

1 Like

I went with the “idea” of short long lived refresh tokens and short lived access tokens so they each have their own genserver and their own supervisor

1 Like

If you get a lot of reads, these processes might become the bottleneck very quickly. I would suggest using ets tables for storing the tokens, since they allow for concurrent reads.

1 Like

it may be the case because of it being serial but it would have to be A LOT of reads because it just does key lookup on a map. But yes that’s definitely something I am thinking about for the next version. That or a dynamicSupervisor that creates a genserver process for each “session”

1 Like

would have to be A LOT of reads

It just said “service” in its description, so I assumed it gets a lot of reads … There is a library, goth which keeps it’s config in a genserver, and it was a bottleneck for me. And I didn’t have A LOT of reads. I used it to generate signed urls for google storage and on each request there were two calls to a single genserver (Goth.Config)… I first moved it to ets, and then to compiled modules, since the config rarely changes. The performance gain was quite significant. And it also seemed cleaner, but that’s subjective.

That or a dynamicSupervisor that creates a genserver process for each “session”

ets approach would be simpler to implement and probably more efficient.

1 Like

I will probably look into ets or Registry(still ets under the hood) this weekend or next as the logic for the genservers got a little messy anyways.

1 Like

Almost all of them will use Cowboy/Ranch under the hood. Might be a good place to start.

1 Like

Hello there
I learned elixir in a similar way by grinding away and trying things on genserver so I may have a couple useful examples. For a bigger app, here is a section of code in my data project that has several supervisors and genservers for solving a simple need of having a cache with very specific expirey logic (activity counts in a rolling time window):

You can find the the full web project and such easily from there, it has a lot of code ranging from high comfort level down to first learning or powering through objectives to get somewhere.

And here is a simpler and very small library that just handles keeping simple site statistics, that happens to have a genserver implementation in case of wanting to hold stats in memory instead of a database.

Hope they help. I can post code snippets of Flow usages that I used at work recently as well if your interested. I’ll do my best to answer any questions if you do take a look.

And welcome to elixir world :slight_smile:

1 Like

Wow! Thanks guys @subetei @entone @jordiee @idi527 !

Really appreciate the help


Hi again, could I take you up on your offer of screen shots of Flow in action when you have a minute or two?

Thanks and have a great weekend all!

I don’t know if this is what you’re looking for but here’s an example of Flow from over a year or more ago.

Flow is used to ingest hangman dictionary words in parallel and puts them into ETS while computing statistics…

I just got around updating a bunch of my elixir projects with the new mix format and remembered about these files. Theres also tons of OTP in this particular project. Have fun… Bibek