TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Case Against Ecto.Multi

1 pointsby lobo_tuertoover 1 year ago

1 comment

bhaneyover 1 year ago
This is more a case against misusing Multi in simple situations that don&#x27;t call for it at all. If you just want to run a sequence of simple queries in a transaction, then that&#x27;s what passing a function to Repo.transaction is for, and you&#x27;re obviously just adding unnecessary complexity by bundling that kind of thing into a Multi for no reason.<p>If you&#x27;re aggregating a collection of results from remote nodes into a stream that transforms each one as they come in into a group of potentially inter-dependent queries that might not need to run at all, then you might want to reduce over that stream and accumulate into a Multi, then maybe even discard the whole Multi if a critical remote node dies in the middle or the results just aren&#x27;t useful. If you try to use a Repo.transaction function for that, you&#x27;re either wasting database resources by running half a doomed transaction and rolling back, or you&#x27;re hand-rolling a &quot;collection&quot; of yet-to-be-run queries (and essentially reinventing Multi).<p>Multis are specifically for grouping and manipulating a plan of execution. They are not meant to be Ecto&#x27;s general interface to transactions, and of course you&#x27;re going to end up with frequently awkward code if you use them like that.