Best practices to handle high concurrency?

I want to create a service for online exams that will handle a minimum of 10,000 concurrencies. if i use phoenix as rest api is there any best practice to handle high concurrency ?

Thanks! :smiley:

My wild guess is that the database could be the bottleneck. So, instead of writing to DB immediately, maybe we can start a bunch of GenServers to accumulate the answers and slowly write them to DB.

:wave:

I would start with a simple setup and measure it under some synthetic benchmark. 10k connections is not much these days (but might still require modifying ulimits) and modern databases can handle 10k reqs / second on commodity hardware.

So if you plan to run on Linux and use a PostgreSQL database:

  • write a simple Elixir app and measure its performance under load with Benchee and k6 or wrk
  • tune PostgreSQL if you run it yourself: https://pgtune.leopard.in.ua
  • tune Linux kernel to allow for more connections / file descriptors than the default
7 Likes