How to host a gen_server as a standalone node using rebar3 release?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
A gen_server does not run as a “standalone node” by itself. It runs inside an OTP application, and that application is packaged into a release that boots an Erlang node with the right applications started. So the real task is to build a small OTP application around the server and then let rebar3 release produce a runnable node.
Start with an OTP Application, Not Only a Module
A gen_server module is only one process implementation. To host it properly, you also need:
- an application module,
- a supervisor,
- release configuration,
- and a start command that boots the release.
A minimal project can be created with rebar3 new app.
That gives you the OTP application structure that a release expects.
Put the gen_server Under a Supervisor
A release should not start an orphan process manually in the shell. It should start the application, and the application should start a supervisor, which then starts the gen_server.
A simple server module might look like this.
Then add a supervisor that starts it.
That structure gives you a real OTP process tree rather than a one-off shell process.
Make Sure the Application Starts the Supervisor
Your application callback module should hand control to the supervisor.
This is the point where the release and the gen_server connect. When the application starts, the supervisor starts. When the supervisor starts, the gen_server starts.
Configure the Release in rebar.config
rebar3 needs to know which application belongs in the release.
Then build the release.
The runnable node lands under _build/default/rel/myserver/.
Run the Node and Interact with It
Start the release in the foreground first. It is easier to debug that way.
For an interactive shell, use:
Once the node is up, you can call the registered server from the Erlang shell.
That is what “hosting the gen_server as a standalone node” really means: the release boots a self-contained node that starts your OTP application automatically.
Common Pitfalls
- Treating a
gen_servermodule as deployable without wrapping it in an OTP application and supervisor. - Starting the server manually in the shell instead of from the application start callback.
- Forgetting to include the application in the release definition.
- Testing only in
consolemode and not verifying that the release boots correctly inforegroundmode. - Skipping supervision and then losing the resilience benefits that OTP is supposed to provide.
Summary
- A
gen_serveris hosted properly by packaging an OTP application into arebar3release. - The correct structure is
application -> supervisor -> gen_server. - '
rebar3 releasecreates a runnable node under_build/default/rel/....' - Use
foregroundorconsoleto start and inspect the node. - The release is the standalone unit, not the
gen_servermodule by itself.
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.