Understanding Actor Model for Node developers

Mohamad Fadhil
3 min readAug 14, 2024

Introduction to actor model in NodeJS

Photo by Ivan N on Unsplash

How programming typically looks like

If you ask any web developer which programming language(s) they use, most will likely say they write code in Javascript/Typescript, PHP, Python, Go, or Ruby.

This code snippet shows how to write a script validating URLs using NodeJS.

const urlChecker = (url) => {
fetch(url)
.then((res) => {
if (res.status == 200) {
console.log(`${url} is valid`)
}
}).catch(() => { })
}

const urls = [
'https://fadhil-blog.dev',
'https://invalid.url'
]

for (const url of urls) {
urlChecker(url)
}

The code is simple and sweet. Basic programming 101, and this programming model works for most cases.

What is the Actor model

I’m skipping the formal introduction of the Actor model, which relates to the mathematical model. If you’re interested in that, you can read its history on Wikipedia

Actor is a concurrency model where you write software that each small unit of your system runs independently and communicates by passing messages. This way, each tiny Actor can run on all cores concurrently.

--

--