Why You Shouldn't Wrap a Stream in a Transaction in Elixir
When you need to process a large number of records in Elixir, the instinct is often to wrap everything in a transaction. All-or-nothing semantics, right? Safe by default. Turns out, this is one of those cases where the “safe” choice creates a bigger problem than the one you were trying to avoid. Here’s what’s actually happening under the hood, and a better approach that’s both safer and more efficient. The Naive Approach Let’s say you have a batch job that needs to process thousands of files, calling an external API for each one and saving the result to the database. ...