L
Logs in the Sky
Beam in Production

The Files, Dependencies, and Configuration a Beam Service Actually Needs

The Files, Dependencies, and Configuration a Beam Service Actually Needs
Organize Beam service files, Python dependencies, runtime settings, secrets, and model artifacts, then verify the package on a fresh worker.

For Beam container image configuration, I separate what builds the environment from what the service reads while running. Python packages belong in the image recipe; credentials and changing model artifacts need their own handling. That separation makes a small service easier to rebuild without accidentally carrying an entire development machine into the cloud.

I would start with one entrypoint, one dependency list, one configuration note, and one harmless request fixture. More files become useful when they acquire a clear responsibility. A dozen configuration files do not make an untested deployment reproducible.

Give each file a job

Imagine a small text-classification endpoint. I would organize its first version around the following responsibilities, adding directories only when the code needs them:

Item

Responsibility

Keep out

app.py

Beam decorator, image definition, handler

Credentials and downloaded weights

requirements.txt

Remote Python dependency versions

A complete dump of an unrelated laptop environment

classifier.py

Application logic, once substantial

Infrastructure setup performed during import

request.json

Synthetic example input

Customer or patient records

README.md

Run, deploy, configure, and verify instructions

Unexplained commands copied from an old service

.beamignore

Explicit upload exclusions

An assumption that excluded files exist remotely

The table describes a project layout, not six universally mandatory files. A tiny handler may reasonably stay in one module. I would split application logic when doing so improves testing or keeps the deployment declaration readable.

The request fixture matters more than it looks. Without it, a teammate can reproduce the image and still test a different input. I would include the expected response shape and any deliberately variable values beside that fixture, so a successful HTTP response is not mistaken for correct behavior.

Upload exclusions deserve the same review. I would exclude virtual environments, caches, private data, and generated outputs, then confirm that required helper modules and fixtures remain available. An aggressively short upload is only useful when it still contains everything the entrypoint needs.

Make the Python choice explicit

I would set the Beam Python version rather than inherit a default that nobody remembers. The interpreter must be compatible with both application syntax and the packages being installed. A package that supports one Python release may lack a compatible binary wheel for another.

This small example follows the configuration forms in Beam’s container image documentation:

from beam import Image, endpoint

image = Image(
    python_version="python3.11",
    python_packages="requirements.txt",
)

@endpoint(image=image, cpu=1, memory="1Gi")
def inspect(**inputs):
    import numpy as np
    values = np.asarray(inputs["values"], dtype=float)
    return {"count": int(values.size)}

For this configuration illustration, requirements.txt contains:

numpy==2.2.0

That version is a concrete example, not a claim that it is the newest or the right dependency for your model. The handler counts values; it does not perform inference or validate an unrestricted public payload. I would first establish the environment with this narrow operation, then introduce the actual model and its input checks.

The memory setting describes container RAM, not GPU VRAM. I would budget host memory for imports, decoding, and model preparation separately from accelerator memory. Confusing those budgets can send an otherwise sensible configuration in the wrong direction.

Treat Python packages and system dependencies separately

For Beam Python dependencies, I want to know which imports are direct application needs and which arrive through other packages. Beam add_python_packages is convenient for a short list; a requirements file becomes easier to review as that list grows. I would choose one clear source for the dependency set rather than maintain two diverging lists.

Pinning direct dependencies limits surprise upgrades, but does not by itself freeze every transitive dependency. The pip guide to repeatable installs describes progressively stronger controls, including pinned dependency sets and hashes. I would generate any resolved list in a clean environment compatible with the target platform, then retain it with the code revision.

System dependencies are different. An audio decoder executable, a shared library, and a Python wrapper can be three separate requirements. Installing the wrapper does not prove that the executable or library is available. I would add an operating-system package only when the application or its documented installation requirements establish that need.

A Beam custom image is worth considering when the default environment cannot supply the required stack cleanly. It also introduces a base-image dependency that needs maintenance. I would record the base reference and why it exists, rather than choose a large CUDA development image simply because the service might eventually use a GPU.

For a Python-only CPU service, that extra image machinery can be unnecessary. For a GPU service, framework binaries, CUDA libraries, and the host driver need a compatible arrangement. I would handle that as an explicit compatibility decision instead of installing more packages until an import stops failing.

Hands sorting illustrated Python and system-dependency cards into two worn wooden trays.

Keep runtime values out of the reusable image

A dependency version changes how the program runs. An API credential authorizes it to do something. I would not manage those two values through the same file merely because both can be represented as strings.

Beam’s secret documentation shows named secrets bound to workloads. For endpoints, the bound values are available as environment variables. That makes them accessible to application code, which means logging the environment wholesale is still a disclosure risk.

My configuration note would list names and purposes, without values:

  • Required credential names and which upstream service uses them.

  • Nonsecret settings, their defaults, and allowed ranges.

  • Model identifier and exact revision to load.

  • Persistent cache location and temporary working location.

  • Which changes require a new deployment to take effect.

I would also distinguish a missing setting from an empty one. A required model identifier should fail with a concise configuration error before the handler accepts work. Silently falling back to a different model makes successful responses harder to interpret.

Hands fastening a padlock on a worn metal document box inside a home cabinet.

For local development, an ignored environment file may be useful, but its presence does not configure a remote worker. I would verify the remote binding by checking that the expected variable exists, without printing its contents. Secret storage helps with distribution; it does not replace careful application handling.

Place weights and caches deliberately

Model artifacts deserve a lifecycle separate from Python dependencies. Rebuilding an image to update a small application file should not automatically mean downloading an untracked model revision again. Equally, a persistent cache should not decide which model revision the service happens to use.

Beam’s volume documentation distinguishes persistent volume files from temporary container files. I would use a deliberate cache path for reusable artifacts and temporary storage for disposable intermediate data. A path on my laptop is not evidence that the same file exists inside the worker.

For the classifier, I would record the artifact identifier, revision, expected files, and loading path. If several workers may populate the cache, I would check how the model library handles concurrent downloads. A partially written artifact should not become the apparent completed cache entry for another worker.

I would load shared model state once per worker when appropriate, rather than once per request. That saves repeated work, but keeps memory occupied while the worker lives. A cache on disk and an initialized model in memory solve different problems; having the first does not establish the second.

Prove the package with a fresh worker

Before sharing the endpoint, I would use a short acceptance sequence:

  1. Build from the recorded interpreter and dependency inputs.

  2. Start a fresh remote worker and confirm required configuration names exist.

  3. Invoke the synthetic fixture and check its output contract.

  4. Repeat the request to exercise the initialized worker.

  5. Check logs for accidental secret or sensitive-input disclosure.

  6. Save the deployment identifier and the exact verification command.

Beam’s endpoint guide documents the FILE:ENTRY_POINT deployment form. For the example above, the target would be beam deploy app.py:inspect. I would keep that command with the project instead of relying on shell history.

A fresh build may still depend on external package indexes or model hosting. Recording references makes those dependencies visible; it does not guarantee their future availability. If rebuild reliability matters enough, I would evaluate retaining approved artifacts rather than calling a version list a complete recovery plan.

Open your service directory and assign each file to code, environment, configuration, artifact, or verification. The first file that fits none of those jobs is the one I would investigate before adding another dependency.

Last revised · 2026-10-23 14:47
Letters
Readers Write

No letters yet — be the first to write.

Write a letter
© 2026 Logs in the Sky. Logs in the Sky