Language Atlas (mini-courses for more languages) Module 10
Gleam on the BEAM and in JavaScript interview questions
Interview questions on gleam on the BEAM and in JavaScript: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
What are gleam.toml and manifest.toml, and which of them do you commit?
Answered in the lesson Gleam on Erlang/OTP 29 and Node.js: first project
-
Fresher to mid
How does Gleam handle an operation that can fail, without exceptions?
Answered in the lesson Gleam for JavaScript and Python developers
-
Fresher to mid
What is a subject in Gleam, and why does Gleam send messages through one instead of to a process id?
-
Fresher to mid
Why does the booking core take the time as an argument instead of reading the clock?
Answered in the lesson Project: a ticket-booking core in Gleam
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to staff
A new Gleam project has two parts: a service that keeps every show's state in memory and serves thousands of requests a second, and form checks that must give the same results in the browser and on the server. Which target or targets does each part use, and how do you lay out the code?
- What it tests
- Matching targets to runtimes, knowing what exists only on the BEAM, the integer difference between the targets, and structuring a package so a shared core builds for both.
- First step
- Split the decision by part. The service needs processes and actors, which exist only on the BEAM, so it uses the Erlang target. The form checks must run in a browser, which needs the JavaScript target, and on the server, so they are a pure module that builds for both, with every number kept well below 2^53 and tests run with gleam test on each target.
- Follow-ups
-
- How do you stop someone from adding a call into gleam_erlang to the shared module?
- Where would large whole numbers, such as amounts in paise, change your plan?
- What would make you run the service on the JavaScript target instead?
From the lesson Gleam on Erlang/OTP 29 and Node.js: first project
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to senior
A Python service splits a bill two ways with share = (total - discount) // 2, and the port to Gleam reads { total - discount } / 2. Every test passes, yet a refund of -7 now gives -3 each where Python gave -4. Explain the difference, fix the port, and say how you would have caught it.
- What it tests
- Truncating against floor division, the sign of a remainder, Gleam's floor_divide and modulo, and tests that cover negative values and the zero divisor when numeric code moves between languages.
- First step
- Compare the two operators on the failing value. Python's // rounds down, so -7 // 2 is -4; Gleam's / on Ints drops the fraction towards zero, so -7 / 2 is -3. They agree when both numbers have the same sign or the division is exact. Python's result is int.floor_divide(-7, 2), which returns Ok(-4).
- Follow-ups
-
- What happens to the remainder, the paisa that does not split evenly?
- Why does int.floor_divide return a Result?
- Which tests would have caught this before the port shipped?
From the lesson Gleam for JavaScript and Python developers
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 2 minutes
-
Mid to staff
A Gleam service keeps each shopping cart in an actor under a supervisor. After a bad deploy, users report empty carts that nobody cleared, and the logs show crash reports for cart actors. Explain what happened, and redesign it so that a crash never loses what a customer added.
- What it tests
- Knowing that a restart starts from the initial state, reading crash and supervisor reports, restart intensity, and where durable state belongs in an actor design.
- First step
- Connect the two symptoms: a supervisor restarts a crashed actor by calling its start function again, so the new process begins with the starting state, an empty cart. The carts were not cleared; they died with the processes that held them. The reports confirm it: a crash report per cart actor, then child_terminated from the supervisor.
- Follow-ups
-
- Why did the actors keep working by name after the restart?
- Where should the cart be written, and when?
- What would a crash loop on every cart do to the whole service?
From the lesson Gleam processes, actors and FFI
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A Gleam service binds an Erlang library function with @external, typed fn(String) -> Int. Its tests pass, but in production some requests crash with erlang:error(Badarg). The Gleam compiler never warned. Why, how do you find the bad input, and how do you fix the binding for good?
- What it tests
- Understanding that externals are trusted, the BEAM forms of Gleam types, reading the foreign function's documentation, wrapping a foreign function, and testing a binding on every target it claims.
- First step
- Start from the rule the language tour states: the compiler cannot see the types of foreign functions, so it trusts the annotation, and a wrong one fails at run time. Read the Erlang function's documentation for what it accepts and returns, and compare that with what a Gleam String is on the BEAM, a UTF-8 binary.
- Follow-ups
-
- Why did the tests not catch it?
- What does a safe wrapper look like?
- Would the same binding fail the same way on JavaScript?
From the lesson Gleam processes, actors and FFI
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to staff
After a release of the booking service, two customers turn up with tickets for the same seat. The service keeps one actor per show and its core is pure. How do you trace what let it happen, and what would you check first?
- What it tests
- Knowing where a one-actor design can still race, reading the message types as the place where decisions are split, and checking the process layout for two owners of one show.
- First step
- Ask how two decisions about one seat could both succeed. Inside one Hold handled by one actor they cannot, so look for a gap: a message pair that checks and then changes, such as an availability check followed by a write, or two actors that each believe they own the show. Compare the release's message types and the process tree with the last good release.
- Follow-ups
-
- The new release added a fast path that sells straight from the page's availability list. What happened?
- How could two actors end up owning the same show?
- Which test would have caught it before the release?
From the lesson Project: a ticket-booking core in Gleam
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
The booking service grows to 300 shows on sale at once. Design how processes are started, found and supervised, and what must survive a crash of one show's actor, given that holds last 10 minutes and confirmed sales must never be lost.
- What it tests
- Applying actors, supervisors and restarts to a real design: dynamic children, finding them without dynamic atoms, restart limits, and which state is durable and which may be lost.
- First step
- Keep one actor per show, because shows share no seats, and start them as needed under gleam_otp's factory supervisor. Find them through a registry, such as an actor holding a dict from show id to subject, not a process.new_name per show, since names are atoms that must not be created dynamically. Then decide what a restart may lose.
- Follow-ups
-
- What may a crash lose, and what must it never lose?
- What happens when one show's actor crashes in a loop?
- Where is the clock read in this design?
From the lesson Project: a ticket-booking core in Gleam
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
All Language Atlas (mini-courses for more languages) interview questions · The Language Atlas (mini-courses for more languages) track