“Rinha de Backend” aka Backend Dogfight was something that started on twitter (I guess) last year and I completely missed. Now I’m trying the second edition and I want to have fun with it.
tl;dr: its a simple web backend that you can POST to charge a customer and GET to see their balance and latest transaction, every other CRUD operation is not considered. You must have a load balancer and two nodes.
My Stack
- Elixir Phoenix
- SQLite (heck yea)
- LiteFS (maybe I’ll try corrosion? Or someone else can take over)
Note: this is a write heavy use case, litefs shines in read heavy use cases. That’s the fun part!
Where am I at?
I just coded the basics of the endpoints a few days ago and today I run the gatling test for the first time but using just one node to see how that goes and…
57% error 500s!
Looking at the logs the major culprit (could not be the only one, idk so far):
08:25:17.750 request_id=F7IuHpb1FlDiO4IACc0h [error] GenServer #PID<0.30517.1> terminating
** (Exqlite.Error) Database busy
INSERT INTO "transactions" ("customer_id","description","type","value","inserted_at") VALUES (?,?,?,?,?) RETURNING "id"
(ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto 3.11.1) lib/ecto/repo/schema.ex:775: Ecto.Repo.Schema.apply/4
(ecto 3.11.1) lib/ecto/repo/schema.ex:377: anonymous fn/15 in Ecto.Repo.Schema.do_insert/4
(ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1358: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
(db_connection 2.6.0) lib/db_connection.ex:1710: DBConnection.run_transaction/4
(backend_fight 0.1.0) lib/backend_fight/bank.ex:208: BackendFight.Bank.create_transaction/2
(backend_fight 0.1.0) lib/backend_fight_web/controllers/transaction_controller.ex:16: BackendFightWeb.TransactionController.create/2
(backend_fight 0.1.0) lib/backend_fight_web/controllers/transaction_controller.ex:1: BackendFightWeb.TransactionController.action/2
Yay write heavy!
Well this is not the end, there’s load of stuff to do so I’ll keep posting on this thread as I got. The last submission date is 2024-03-10T23:59:59-03:00
so Im good for now.