elixir python migration

FastAPI vs Elixir: When to Switch and When to Stay

Daniil Popov November 26, 2026

FastAPI vs Elixir: I replaced one with the other

We took over a B2B accounting SaaS. FastAPI backend, React frontend, a Java workflow engine called Zeebe, six Docker services and three developers keeping it alive. We rebuilt it in Elixir and Phoenix in three weeks. 63% less code, 76% fewer files, 83% fewer Docker services (six became one). Full breakdown here.

So yes, I'm biased. I run an Elixir agency. But FastAPI wasn't the problem in that project. The pile of services around it was, and that difference is the whole article.

Short version: if your product is an API in front of Python models, stay on FastAPI. If it grew websockets, Celery, Redis and a separate React app around a small API, Elixir will probably save you a lot of code and a few headaches. You can also keep both.

What's the plan?

  • Side by side table
  • Concurrency: asyncio vs BEAM processes
  • Websockets and real time
  • "Elixir vs REST API" and "gRPC vs Phoenix"
  • Celery vs Oban
  • Typing, tooling, hiring
  • ML and AI, where Python wins
  • Deployment and cost
  • When to stay, when to move, how to migrate

Side by side

FastAPI (Python) Elixir + Phoenix
Concurrency asyncio event loop per process, plus N worker processes Light BEAM processes, one per request or connection, preemptive scheduler, all cores in one OS process
Blocking call Blocks that worker's event loop if called inside async def Blocks only its own process
Websockets Supported, fan-out across workers needs Redis or similar Channels and LiveView, PubSub works across nodes without Redis
Background jobs BackgroundTasks, or Celery with RabbitMQ or Redis Oban, jobs live in your database
Typing Type hints, Pydantic, OpenAPI docs for free Dynamic, compiler infers and checks types (Elixir 1.20)
ML and AI Best ecosystem there is Nx and Bumblebee for some, call Python for the rest
Hiring pool Huge Small, people learn it fast
Production App workers, Celery workers, broker, cache, often a frontend app One release and a database

Let's go row by row.

Concurrency: event loop vs BEAM processes

FastAPI runs on an asyncio event loop. One Python process, one loop, many coroutines. They take turns every time they hit an await. For I/O, like waiting on Postgres or another HTTP service, it works well.

Catch: taking turns is voluntary. The FastAPI docs explain it properly. A plain def path function runs in a threadpool, so it doesn't block the server. But write async def, call a blocking library inside, and every request on that worker waits for you. Easy to write, hard to spot in review.

{@code}

For more CPU cores you start more processes. The deployment docs show fastapi run --workers 4 main.py: four separate worker processes, each with its own memory. Your in-memory cache exists four times. Your list of websocket connections exists four times, and the copies don't know about each other. That's why Python stacks get Redis so early.

Python is moving here too. Since 3.14 the free-threaded build (no GIL) is officially supported but still optional, and the release notes say single threaded code pays roughly 5 to 10% for it. Good news. It's still a separate build you opt into, and asyncio still schedules coroutines the same way. On that build, plain def endpoints in the threadpool can use several cores in one process, if your C extensions support it.

Elixir code runs in BEAM processes. Not OS processes, not threads. The Elixir guide calls them extremely lightweight and isolated, and says tens or even hundreds of thousands running at once is not unusual. Phoenix gives every connection, including every websocket, its own one.

The scheduler is preemptive. It counts work in reductions and switches when a process has used its budget (good deep dive here). There is no await to forget, so one slow request can't freeze the rest. (Native code called through NIFs is the exception.) By default you get a scheduler per CPU core, so one OS process uses the whole machine and one in-memory cache serves every request on that node. No worker count to tune.

To be fair: a plain CRUD JSON API under normal load is fast enough on both. You feel the difference with long lived connections, slow third party calls and CPU spikes. Then you feel it a lot.

Websockets and real time

FastAPI does websockets. The docs have a chat example that keeps connections in a Python list, followed by a tip that it will only work with a single process. For more they point to encode/broadcaster, backed by Redis or PostgreSQL. So with four workers, a message on worker 1 travels through Redis to reach a user on worker 3.

{@code}

Same thing as a Phoenix channel:

{@code}

Line count is similar. What matters is broadcast!. It goes through Phoenix PubSub, and the channels guide says broadcasts work even if the app runs on several nodes, over native Erlang VM messaging. Redis is there for hosts where nodes can't talk to each other. Optional.

How far does it go? In 2015 the Phoenix team held 2 million websocket connections on one server. A big one, 40 cores and 128 GB of RAM, and the benchmark is old. Read it as "the ceiling is far away", not as a number for your app.

Then LiveView. It renders interactive UI from the server over a websocket, so a lot of products don't need a React app and a JSON API in between. In our migration the frontend went from 18,797 lines to 1,330. That one change explains most of the code we deleted.

"Elixir vs REST API" and "gRPC vs Phoenix"

People search for these, so quick answer: they aren't opposites. Phoenix serves REST and JSON like FastAPI does. Need a public API for a mobile app or partners? Phoenix controllers, done.

gRPC is a protocol, not a framework, and Elixir has a full gRPC implementation with client, server and streaming. The real question behind "gRPC vs Phoenix" is whether your services need to talk over the network at all.

Often they don't. In our project gRPC existed only so FastAPI could talk to Zeebe, and 53 REST route files existed only so React could talk to FastAPI. In one Elixir app those became function calls. We didn't port the API, we deleted it. Best kind of commit.

Background jobs: Celery vs Oban

FastAPI has BackgroundTasks for small stuff. For heavy work its own docs suggest bigger tools like Celery, which need a message queue like RabbitMQ or Redis. Celery says the same: it requires a message transport. So now you run the API, a broker, Celery workers, and Celery beat if you have schedules.

{@code}

In Elixir most teams use Oban. Oban stores jobs inside your primary database, with engines for PostgreSQL, MySQL and SQLite. No broker. Workers run inside your app.

{@code}

Return an error from perform and Oban retries with backoff. Jobs sit in your database, so you can insert one in the same transaction as the data it works on. Both commit or neither does. With a separate broker you have to work for that. Python has PostgreSQL based queues too, like Procrastinate, if you want to skip the broker.

In our migration Oban replaced the whole Zeebe setup: the engine, its monitoring UI and Elasticsearch. Funny part: Elasticsearch was in production only because Zeebe needed somewhere to export. Nothing else used it.

Typing and tooling

FastAPI is really good here and I'll say it plainly. You write type hints, Pydantic validates the request, and you get OpenAPI docs at /docs for free. Add mypy or pyright, Ruff and uv, and Python tooling today is very good.

Elixir is dynamic, but that's changing fast. Elixir 1.20 is now a gradually typed language. The compiler infers and checks types for every program without annotations. Type signatures you write yourself are planned for later, with no date yet. Request validation is Ecto changesets, explicit and solid, but no free OpenAPI page like FastAPI gives you.

Tooling is a different philosophy. In Python you pick a package manager, formatter, linter, test runner and type checker. In Elixir mix builds, fetches deps, formats and runs tests, and ExUnit ships with the language. Less choice, less config. Some people love picking tools. I don't.

Ecosystem and hiring

No contest on size. In the 2025 Stack Overflow survey 57.9% of respondents use Python and 2.7% use Elixir. For web frameworks it's 14.8% FastAPI and 2.4% Phoenix. Need ten people next month with the exact stack on their CV? Python wins.

It's less scary than it looks. You need fewer people, because one engineer owns a feature from database to screen. And you can train them. Remote hires senior engineers whether they know Elixir or not, and their internal training typically takes two to four weeks. Their engineering org is nearly 300 people.

For the web part, the ecosystem has what you need: Phoenix, Ecto, Oban, auth, payments, email, telemetry. It gets thin on vendor SDKs. Some vendors ship Python only, and then you call their HTTP API with Req yourself. Annoying, rarely a blocker.

ML and AI: Python wins

If your product is the model, stay in Python. PyTorch, Hugging Face, research code, notebooks, the people who know them: all Python. Nothing in Elixir replaces that and I won't pretend it does.

Elixir has real options for part of it. Nx gives you tensors with XLA and LibTorch backends. Bumblebee loads pre-trained models from Hugging Face, as long as it implements that architecture. Fine for serving common models inside your app. Not a place for training work.

And you can mix. Pythonx embeds the Python interpreter in the Erlang VM. Its authors are upfront about the GIL: calls from many Elixir processes don't run Python in parallel. My rule of thumb is simpler. Keep the Python model service, let Elixir own the product around it. In a lot of "AI products" most of the code is users, billing and jobs, and the model is an HTTP call that looks the same from both languages.

Deployment and running cost

I won't give you a cloud bill comparison. I don't have a fair one. I can show you what you run.

A grown FastAPI product usually has app containers with a few workers each, Celery workers, Celery beat, Redis or RabbitMQ, the database, and often a separate frontend build. Each one needs monitoring and patches.

A Phoenix app ships as one release. One BEAM per server handles requests, websockets, jobs and caches, and talks to the database. Our migration went from six Docker services to one, and infrastructure config from 5,448 lines to 439. The saving is in the parts you no longer run, more than in raw speed.

When to stay on FastAPI

  • The service is a thin API in front of Python models or data pipelines.
  • Your team knows Python, ships fine, nothing hurts.
  • Many external consumers rely on your generated OpenAPI docs.
  • You depend on Python only SDKs you can't replace.
  • There's no time for learning right now. A switch costs something, be honest about that.

When to move to Elixir

  • You run websockets, live dashboards or notifications and fight Redis to keep workers in sync.
  • Background work grew into Celery, a broker and beat, and failed jobs keep you busy.
  • A small feature means changes in FastAPI, React and a worker, in three repos.
  • Frontend and backend people can't cover for each other.
  • Infrastructure takes more of your week than the product.

Several of those true? The switch usually pays for itself. This is what a full Elixir stack looks like. Comparing more options: Elixir vs Node.js and Elixir vs Rails.

How a module by module migration works

No big bang needed. Our three weeks were a full rebuild because the product was small enough. Most teams should go step by step. The general method is in our modernization guide. For FastAPI it looks like this:

  1. Start with the schema, not the code. Point Ecto at the same Postgres and map the tables. Schemas are honest about what the system does.
  2. Put Phoenix next to FastAPI behind the same load balancer. Route one path prefix to Phoenix, leave the rest.
  3. Move what hurts most first. Usually real time or jobs: one Celery queue becomes an Oban worker, one websocket endpoint becomes a channel.
  4. Keep Python where Python is best. Inference stays a Python service that Elixir calls over HTTP.
  5. Move pages and endpoints one by one. When the last route leaves FastAPI, switch it off. Then delete Redis and the broker.

Every step ships on its own and can be rolled back. Stop halfway and you still have a working product. How we run these: migration page.

FAQ

Is Elixir faster than FastAPI?

For simple JSON requests under normal load you won't notice. Elixir pulls ahead when you hold many long lived connections or mix slow calls with fast ones. I don't have a fair benchmark of my own, so I won't quote one.

Can Elixir replace Celery?

Yes. Oban does queues, retries, scheduling and unique jobs, stores them in your database and runs inside your app. No broker.

Can I use Python ML models from Elixir?

Yes. Call a Python service over HTTP, embed Python with Pythonx, or run supported models natively with Bumblebee. For heavy or custom ML, keep Python.

Is it hard to hire Elixir developers?

The pool is smaller. Remote hires strong seniors and trains them in two to four weeks. You also need fewer people for the same product.

Does Phoenix do REST APIs and gRPC?

Both. Controllers serve JSON, elixir-grpc covers gRPC with streaming. Better question: do you need an internal API at all?

How long does a FastAPI to Elixir migration take?

Ours, a production SaaS on FastAPI, React and Zeebe, took three weeks to full parity. Bigger systems take longer and should move module by module.

Not sure which side you're on?

We start with a paid technical assessment. We look at your FastAPI app, what hurts and what doesn't, and tell you if moving makes sense. Sometimes the answer is "stay". FastAPI is a good framework. It just shouldn't need six services around it.

Share