I'm running a simple Python application that exposes a single HTTP endpoint, and I need to run it within a container using minimal memory. Right now, I'm using uvicorn, which starts up consuming about 600MB of RAM. This seems excessive, especially since a Node.js container only uses around 128MB and a full phpMyAdmin setup requires just 20MB! I know comparisons can be tricky, but with current RAM prices, a 30x difference is significant. Any suggestions for a more memory-efficient way to run my endpoint?
5 Answers
If you really need low memory, have you considered switching to Go? It's generally easier to work with when it comes to memory usage, and you could keep the container size under 10MB!
That RAM usage seems excessive, especially for a simple app! Just to clarify, is that the memory usage while containerized? How much of it is just the container startup overhead?
What base image are you using for your container? It could affect your RAM usage significantly.
I'm currently using python:3.13-slim.
Are you using frameworks like FastAPI or Flask? They may have different memory footprints to consider.
I've noticed that uvicorn shouldn't use that much memory on its own. Have you checked if your application is holding on to memory for requests? Also, look into Bjoern, it’s a lightweight HTTP server for Python that could help you out! You might also want to give bottle.py or the built-in Python HTTP server a try.

I need Python because various libraries I rely on require it; switching to Go wouldn't work in this case.