Can we go back to the concept of runtimes, for JavaScript say? I know Node.js is the runtime on the server side, and I want to know how that differs from PHP. I'm listening to a video about how PHP serves a web page, and I've worked with Node so much that I'd forgotten other languages do much the same thing, running on the server. So a quick refresher. Then back to what a runtime is, because I want the idea to set: when I think about agents, I break them into a model, a runtime and the environment it runs in. That's where this is all coming from.
What a runtime is. A language on its own is rules for writing code. To run it you need an that executes it, built-in abilities to touch the outside world, and something that decides when things run. That bundle is the . Node is V8, Chrome's engine, plus files, network and an . The browser is a runtime too: the same kind of engine, with the page and fetch and no file system.
PHP and Node. PHP has its own runtime, so at that level they are the same kind of thing. The difference is the lifecycle. Classic PHP runs per request: the web server hands the request to PHP, your script runs top to bottom, prints HTML, and everything in memory is thrown away. Node is the other way round: your program is the server. You start it once and it handles request after request, keeping what's in memory.
- Model and engine. Both are the core that can't touch anything alone.
- Runtime and runtime. The layer that gives the core hands and runs the loop.
- Environment and environment. Where it all lives: a laptop, a container, a Vercel function.
Instead of runtime and runtime, I think a better comparison is the harness, what we had before. In the context of a runtime, it's the tools that come bundled with it. Node.js comes with built-in tools that touch the file system, the network and so on, while the runtime in the browser has no file system, but has the network and, I think, the DOM.
Yes, that's a cleaner mapping. The is to the model what the bundled APIs are to the engine: the set of things the core is allowed to reach. Node gives files, network and processes, and no DOM. The browser gives the network, the DOM and storage, and only sees a file you pick.
- 1Page
- 2Network
- 3Files
- 4Timers
- 5Processes
- 6Storage
- Engine
- V8
- Loop
- Event loop, while the program runs
Keep one more thing in the harness: the loop. Node's event loop decides when your code runs and brings results back from those APIs, the same job an agent harness does when it runs think, call a tool, read the result, go again.
Same engine, different tool belt.
Oh my goodness, this has landed hard!
That's the best feeling: two things you already knew turning out to be one idea. It keeps paying. Meet anything new, Cloudflare Workers, Deno, an agent framework, and ask the same three questions: what's the engine, what tools and loop does it get, and where does it run? Workers are V8 with a harness that has the network and no file system, on Cloudflare's machines.
So what about Rust and Go?
They break the pattern, because they're compiled. A turns the code into machine code ahead of time, and the processor runs the result directly. There's no engine in the middle.
- Go bundles runtime pieces into every program: a garbage collector and a scheduler for goroutines, which plays a part like Node's event loop.
- Rust has almost none. If you want an event loop you choose one as a library, usually Tokio. You pick your own harness.
The practical difference: a Node or PHP app needs Node or PHP installed on the server. A Go or Rust app is one file you copy over and run.
Can we take a step back to the languages I learned about ten years ago, Java, C++, C# or C, which I never really understood at the foundations until today? Interpreted and compiled were always fuzzy words when I was at uni, and now they make sense. For JavaScript, the engine is what does the interpretation so the CPU can run it; that's why we say it's an interpreted language, and it isn't magic any more. And I remember we compiled Java before we ran it, so running a Java program must be running a binary straight on the CPU, with no interpretation. Damn.
The core of that is right: something always translates your code into machine instructions, and the only question is when. Compiled means ahead of time; interpreted means while it runs.
Java is the interesting exception. javac didn't make machine code. It made , a halfway format no processor runs, and java started the JVM, Java's engine, to run it. That's what "write once, run anywhere" meant: the bytecode is the same everywhere, and only the JVM is built for each system. C# works the same way. C and C++ are fully compiled, like Go and Rust.
- 1main.goSource
- 2go buildCompiler
- 3mainMachine code
- 4CPURuns it as it is
All of it is done before shipping. What arrives is machine code, and the processor runs it as it is: nothing else has to be installed.
And modern engines blur it further: V8 and the JVM watch which code runs often and compile it to machine code on the spot (). It's a spectrum of when, not two boxes.
Why isn't there a runtime for Python in the browser?
There is now, through a side door. Browsers agreed on one language in the 1990s, and every attempt at a second died, because nobody writes for one browser: VBScript in Internet Explorer, Dart in an experimental Chrome.
The side door is , a low-level format browsers run at near-native speed. Pyodide compiles Python's own engine into it, so a Python engine runs inside the browser's engine. It costs a download of several megabytes, and Python still reaches the page through JavaScript, because the browser's harness only hands the page to JavaScript.
The other reason this came up is a recent cyberattack, one related to the PHP runtime. Can you search for it, go through it and understand it? As I understand it, the attack was at the runtime level: even an application that was airtight in its own security would still be vulnerable, because the engine running it was the one with the hole.
Found it. It's called PHP2Shell, and you have it right: the flaws are in PHP itself, so a site is exposed even when its own code is secure. They reach back to PHP 5.4.
PHP's engine is written in C, which makes you hand memory back by hand. Hit an error at exactly the wrong moment, here running out of memory, and PHP can be left holding a pointer to memory it already gave back, a . Fill that memory with crafted data and a crash becomes "run my code on your server". The trigger comes before your code runs: session upload progress, on by default.
The upload is tracked before your script starts, and that step has the bug. The attacker's code runs there, with your server's permissions. Your script, written without a flaw, is never reached.
In your terms: the engine had the hole, so it didn't matter how good the code on top was. Like a model behaving perfectly while its harness lets anyone run commands. Fixed in 8.2.35, 8.3.36, 8.4.27 and 8.5.12.
Wait, I feel I have to revisit some other things now that I understand what a runtime actually means. Vercel is built on top of Node.js. Continue from there.
One correction first, because it makes the rest click: Vercel isn't a runtime, it's an . It's the place your code runs, and it offers more than one runtime. Deploying a Next.js site puts code in three places:
- The build. A machine runs Node to execute
next build, which makes files. - Static files. Pages made ahead of time sit on Vercel's CDN. Only the browser runs anything.
- Functions. Whatever stays dynamic runs on demand, on Node by default, or on the Edge runtime: V8 with the browser-style harness,
fetchand no file system. Same engine, smaller harness.
And the lifecycle sits between PHP's and Node's. Vercel starts copies when needed and freezes or drops them when it likes, so you treat memory as disposable.
It's nice you touched on serverless functions. I've always had the concept, but it's still kind of blurry, so can we untangle it? I'm trying to find an angle to ask a specific question from, a starting point, but I don't think I have one. So let's just break it down.
Start with the problem it solves. The old way, you rented a server: a machine on all night, running Node or PHP, paid for at 3am when nobody came, overwhelmed when everyone did, and yours to patch.
Serverless hands the platform a function instead: when a request comes, run this. The platform owns the machines, the runtime, the scaling and the patching. There are still servers; they just aren't yours to think about. In Next.js, a route.ts that exports GET is a .
- 1A box
- 2Node
- 3Your code
Nothing has asked yet. Nothing is running, and nothing is being paid for.
- No memory between requests. Any copy can vanish, so what must last goes in a database or storage.
- Time limits. Functions are for short jobs.
- You pay per use, not for idle hours.
If you want the next angle: where does state live, then?
One last thing. I still haven't wrapped my head around the event loop, and how PHP handles requests. Now that we've built up some knowledge about requests and what PHP and Node.js are, fundamentally speaking, I want to understand how the two handle requests, and the philosophy behind each approach: what problems were they trying to solve?
Picture a restaurant, because the problem is the same: most of a request is waiting, for the database, a file, another API. They differ in what they do during the wait.
PHP: a waiter per table. PHP-FPM keeps a . Each request gets a worker, and while the database is busy that worker stands at the kitchen window. When the page is sent, it's wiped and goes back to the pool. PHP began in 1994 as tools for personal home pages, and it's built so you never think about other requests.
Node: one waiter for the room. One thread runs all your JavaScript. When a request needs the database, Node hands the wait to the system and serves the next table. When the answer comes, a note joins a queue, and the event loop runs the code waiting for it. That's what await means: park me, serve someone else, come back when my data is ready. Ryan Dahl built it in 2009 betting that if waiting cost nothing, one process could hold thousands of connections.
- Last reply
- 240 ms
- Workers held while waiting
- 4 of 4
- Queued for a worker
- 2
PHP buys safety and simplicity by spending resources. Node buys efficiency by asking you never to block the loop.
Ah damn! I also keep hearing threads and processes… urgh! I thought I would close it here, but a hole it is.
A short one, and it's the floor under everything else. A is a running program with memory the system keeps private to it. A is a line of work inside a process, and threads share their process's memory.
A process is a kitchen with its own pantry; threads are cooks in one kitchen, sharing it. More kitchens is safer and expensive. More cooks is cheap, and they bump into each other.
Like PHP-FPM: each worker its own process. Three pantries to fill, and nothing shared.
- PHP-FPM's workers are separate processes: that's where its isolation comes from.
- Node is one process with one main thread for your code, and a few helper threads underneath.
- Go's goroutines are lighter still, juggled over a handful of real threads.
- Chrome keeps pages in separate processes, so one crashing doesn't take the browser down.
Just a bit more. We've talked about containers: when I run something in Docker, it runs in its own container. I know we've discussed what that is, but I think we can revisit it with this new knowledge. Then tell it apart from how this chat is being run right now, because I understand that whenever I start a new chat, some instance is being run on the server side. So how is that different?
A is a process with walls round it. Docker starts an ordinary process and fences it off: its own view of the files, its own network, limits on memory. From inside it looks like a whole machine; from outside it's one more process sharing the kernel. The fills the fence with a runtime, your code and its packages. A fakes a whole computer instead: a separate building, not a walled-off kitchen.
This chat. The model isn't started up for you. It runs on GPU servers shared by huge numbers of conversations; each message sends the whole conversation in, and it reads, replies and keeps nothing. The harness is the app's loop, running tools like web search when asked. The environment is this chat's own sandbox, a fenced-off workspace for files and commands. The instance you imagine is real, but it's the environment and the transcript. The model is the shared engine, one V8 serving everyone.
So why was there a need for interpreted languages like JavaScript or PHP? Why couldn't they just write another compiled language? Where did the idea of an interpreted language come from, and what was it fundamentally helping with, that it's so important?
Because compiling solves the computer's problem, and interpreting solves the human's.
- Portability. A binary runs on one kind of machine. A website has to run on devices that didn't exist when it was built, so it ships source and each browser brings its own engine.
- Safety. A binary can do anything the system allows. Code that goes through an engine can only do what its harness permits, which is why a page can't read your files. ActiveX let pages run native code in the 1990s and was a disaster.
- Speed of trying. Edit a PHP file, refresh, see it. That loop made the web open to designers and beginners.
The costs explain the modern fixes: slower, hence JIT; needs a runtime installed, hence Go's single file; mistakes only show when the code runs, hence TypeScript.
One more thing. There's another chat we had, called Restate infrastructure overview, where we were trying to dissect what the company does. I'd like to go back to it, because I feel things would make a bit more sense now that I understand all this.
It does, because Restate solves the problem we kept hitting tonight. Everything throws memory away: PHP after each request, serverless copies whenever, containers on every deploy. Fine for a request of 200 milliseconds. A disaster for an agent run of twenty minutes that calls the model forty times and waits for you to press Approve.
Restate writes each step to a before moving on, so if the process dies, another picks the run up and carries on from where it stopped: . And it's Node's await at the scale of a cluster. When the agent asks for approval, Restate parks the run and frees the container; when you approve, it wakes the run on whichever container is free.
Aahh, got it now!
Can we get a little bit technical, but on a very simple scale? How does Restate do the journaling you talked about?
One trick: your code wraps every step that touches the outside world in ctx.run, and Restate writes down each step's result before your code may move on.
- First run. Your code reaches a step. The library runs it, sends the result to Restate, Restate appends it to its journal on disk, and only then does your code get the result.
- After a crash. Restate calls the function again, from the top, on any free machine, and sends the journal along. Steps already in it return their saved result at once. The first step that isn't is where the code is live again.
- Waiting. For a sleep or an approval, Restate journals "waiting until" and lets the function end. The machine is free; the replay brings the code back to that line later.
- 1
const plan = await ctx.run("ask model", () => llm.plan(task)); - 2
await ctx.run("write file", () => sandbox.write(plan)); - 3
await ctx.sleep(60_000); - 4
await ctx.run("tell user", () => notify(user));
Restate calls the handler on container A.
The one rule: because the code reruns from the top, everything outside the wrapped steps must do the same thing every time. Math.random() or the time, unwrapped, could send the replay down a different path. Anything unpredictable goes inside ctx.run, so its answer is recorded too.