# Asobi - Open Source Multiplayer Game Backend for Defold

**URL:** <https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612>\
**Category:** Showcases\
**Created:** [April 4, 2026, 12:23pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612 "2026-04-04T12:23:01Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 4, 2026, 12:23pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/1 "2026-04-04T12:23:01Z")

</div>

Hey everyone!

I’ve been building **Asobi** , an open source multiplayer game backend written in Erlang/OTP, and I wanted to share it with the Defold community since we have a Defold SDK and a playable demo.

## What is Asobi?

Asobi is a server-authoritative game backend that handles the boring parts of multiplayer so you can focus on your game:

- **Authentication** - registration, login, session tokens
- **Matchmaking** - queue-based with pluggable strategies (fill, skill-based, custom)
- **Real-time WebSocket** - 10Hz game state broadcast, input at 60fps
- **Leaderboards, chat, presence, economy, inventory**
- **Voting system** - let players vote on game events between rounds
- **Bot AI** - automatic queue filling with Lua-scripted bots
- **Lua scripting** - write your game logic in Lua, no Erlang needed

The backend runs on the BEAM VM (Erlang), which gives you massive concurrency, fault tolerance out of the box.

## Lua Scripting - No Erlang Required

This is the part I’m most excited about for Defold developers. You can write your entire server-side game logic in Lua:

```lua
function init(config)
    return { players = {}, projectiles = {} }
end

function join(player_id, state)
    state.players[player_id] = {
        x = math.random(800), y = math.random(600),
        hp = 100, speed = 4
    }
    return state
end

function handle_input(player_id, input, state)
    local p = state.players[player_id]
    if input.right then p.x = p.x + p.speed end
    if input.left then p.x = p.x - p.speed end
    if input.shoot then
        -- create projectile...
    end
    return state
end

function tick(state)
    -- physics, collisions, win conditions
    return state
end

```

You implement a few callbacks (`init`, `join`, `leave`, `handle_input`, `tick`, `get_state`) and Asobi handles everything else - matchmaking, WebSocket transport, bot spawning, authentication.

## Arena Demo

To prove it works, we built a top-down arena shooter:

- **Server** : Pure Lua scripts, zero Erlang code - [asobi\_arena\_lua](https://github.com/widgrensit/asobi_arena_lua)
- **Client** : Defold - [asobi-defold-demo](https://github.com/widgrensit/asobi-defold-demo)
- **SDK** : Defold Lua module - [asobi-defold](https://github.com/widgrensit/asobi-defold)

The game features:

- 4-10 players per match (bots fill empty slots)
- WASD movement, mouse aim, click to shoot
- 90-second rounds with projectile combat
- Between-round upgrades (boons) for top players
- Player voting on round modifiers (Double Damage, Tight Quarters, etc.)
- Ship sprites and cannonball projectiles

### Running it locally

```bash
# Clone the game server (just Lua scripts + docker-compose)
git clone https://github.com/widgrensit/asobi_arena_lua
cd asobi_arena_lua
docker compose up -d

# Clone and build the Defold client
git clone https://github.com/widgrensit/asobi-defold-demo
cd asobi-defold-demo
ln -s /path/to/asobi-defold/asobi asobi
java -jar bob.jar --platform x86_64-linux resolve build
./build/x86_64-linux/dmengine

```

The client has a server select screen - choose LOCAL to connect to your Docker instance.

## Defold SDK

The [asobi-defold](https://github.com/widgrensit/asobi-defold) SDK is a pure Lua module (no native extensions) that gives you:

- HTTP client for REST APIs (auth, leaderboards, inventory, etc.)
- WebSocket client for real-time gameplay
- Matchmaker integration
- Chat and presence

Drop it into your project as a symlink or copy and you’re good to go.

## A note on AI

Full transparency - I used AI (Claude) to help write the Lua game scripts. The backend platform (Asobi) is more hand-written Erlang but also some AI, but for the arena demo’s Lua code, AI was a great pair programmer.

## Links

- **Asobi backend** : [GitHub - widgrensit/asobi: Game backend platform built on Nova/OTP · GitHub](https://github.com/widgrensit/asobi)
- **Defold SDK** : [GitHub - widgrensit/asobi-defold: Defold client SDK for Asobi game backend · GitHub](https://github.com/widgrensit/asobi-defold)
- **Arena game (Lua)**: [https://github.com/widgrensit/asobi\_arena\_lua](https://github.com/widgrensit/asobi_arena_lua)
- **Arena client (Defold)**: [GitHub - widgrensit/asobi-defold-demo: Defold arena demo for the Asobi game backend · GitHub](https://github.com/widgrensit/asobi-defold-demo)
- **Lua scripting guide** : [asobi/guides/lua-scripting.md at main · widgrensit/asobi · GitHub](https://github.com/widgrensit/asobi/blob/main/guides/lua-scripting.md)

Everything is open source. Would love to hear your feedback and see what you build with it!

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [April 4, 2026, 1:38pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/2 "2026-04-04T13:38:56Z")

</div>

Wow, very cool! Thank you for sharing!

What are your plans for this? Are you creating a game of your own on Asobi?

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 4, 2026, 2:10pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/3 "2026-04-04T14:10:32Z")

</div>

Mostly I wanted to show that Erlang/otp is good for backend.

Maybe depending how things go I will look into hosting service.

But mainly it is fun to build this and see how I maybe can help the gaming community and do commercial for Erlang. 🙂

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 4, 2026, 2:50pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/4 "2026-04-04T14:50:40Z")

</div>

So if anyone want to try this and need help I would be happy to try to build a game with the backend.

---

<div class="post-metadata">

**Author:** ![cenullum](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cenullum/32/40863_2.png) [@cenullum](https://forum.defold.com/u/cenullum)\
**Post date:** [April 5, 2026, 7:35pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/5 "2026-04-05T19:35:41Z")

</div>

Is websocket scalable or I need to do redis part myself ? I saw you use OTP `pg` module as pub/sub. I didnt use pg ever

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 5, 2026, 7:40pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/6 "2026-04-05T19:40:59Z")

</div>

WebSocket (with session cache)

| Metric | Value |
| --- | --- |
| Connections | 4,613 (0 failures) |
| Messages sent+received | 922,600 |
| Throughput | 49K msg/sec |
| RTT p50 | 10.7ms |
| RTT p99 | 31.3ms |
| Memory per connection | ~15KB |
| Delivery | 100% |

Without session cache: 3,522 connections (1,024 failures) — the cache eliminated the auth DB bottleneck. This was that each connection needed to check auth to be sure that the websocket was still a authenticated user. Now the authentication is cached in the node after the first db check.

Key caveats: single node, 8 cores, client and server sharing the same machine (so client steals ~50% CPU). Real deployment estimated at 2-3x higher throughput.

I haven’t tried multi-node yet, it might be slower. But asobi uses postgres job queue for fan out. So a message that needs to be broadcasted is sent to each node that then handles it internally with erlang messages and websockets.

Idea is to try to have a simple setup host + postgres and that should help you started.

---

<div class="post-metadata">

**Author:** ![cenullum](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cenullum/32/40863_2.png) [@cenullum](https://forum.defold.com/u/cenullum)\
**Post date:** [April 5, 2026, 9:07pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/7 "2026-04-05T21:07:08Z")

</div>

15k concurrent connections on a single node looks really solid as a starting point. I think even 1gb ram is enough for this setup

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 5, 2026, 9:14pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/8 "2026-04-05T21:14:30Z")

</div>

I hosted asobi arena play.asobi.dev on [fly.io](http://fly.io) it is two machines with 1cpu shared 1gb. Then they have postgres they share, 4gb ram or so.

I haven tried loadtesting it there but I think benchmarking is hard to get it right.

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 10, 2026, 5:45am UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/9 "2026-04-10T05:45:57Z")

</div>

If anyone want to try Asobi in a game jam or so I am looking into hosting it.

The idea is still very early. 🙂

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 12, 2026, 6:06pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/10 "2026-04-12T18:06:58Z")

</div>

## Updates

Quite a lot has happened since the initial post, so here’s a summary of what’s new.

### asobi\_lua — Standalone Lua Runtime

The Lua scripting layer has been extracted into its own standalone OTP application ([asobi\_lua](https://github.com/widgrensit/asobi_lua)). This is the bit you actually deploy — a single Docker image (`ghcr.io/widgrensit/asobi_lua:latest`) that runs your game logic without touching any Erlang.

It now ships with a full `game.*` Lua API that gives your scripts access to all engine systems:

```lua

-- Economy

game.economy.grant(player_id, "gold", 100, "quest_reward")

game.economy.debit(player_id, "gold", 50, "shop_purchase")

local wallets = game.economy.balance(player_id)

-- Leaderboards

game.leaderboard.submit("weekly_kills", player_id, score)

local top10 = game.leaderboard.top("weekly_kills", 10)

local nearby = game.leaderboard.around("weekly_kills", player_id, 5)

-- Storage (cloud saves)

game.storage.player_set(player_id, "progress", "checkpoint_3", data)

local save = game.storage.player_get(player_id, "progress", "checkpoint_3")

-- Messaging

game.broadcast("boss_spawned", { zone = "north", hp = 5000 })

game.send(player_id, { type = "quest_update", step = 3 })

game.notify(player_id, "reward", "You earned 100 gold!")

game.chat.send(channel_id, sender_id, "gg")

```

### World Server — Large-Scale Spatial Multiplayer

The biggest addition is `asobi_world` — a new game mode for persistent, zone-based worlds (think survival games, MMO-lite, open worlds). The match system is still there for session-based games, but worlds support:

- **Zone partitioning** — the world is split into grid zones, each ticking in parallel

- **Interest-based broadcasting** — players only receive updates from nearby zones

- **Entity persistence** — zone state snapshots to PostgreSQL, survives crashes and restarts

- **Dynamic spawning** — template-based entity spawning with respawn rules, jitter, and max limits

- **Spatial queries** — `query_radius`, `query_rect`, `nearest`, `in_range` for combat, loot, proximity

- **NPC zone crossing** — entities transfer between zones at boundaries

- **Persistent worlds** — world stays alive even when all players leave

The Defold SDK has been updated with `world.list`, `world.create`, `world.join`, `world.find_or_create` and event handlers for `phase_changed` and `world_finished`.

### Phases & Timers

Games can now define multi-phase progression with an optional `phases` callback:

```lua

function phases(config)

return {

{ name = "warmup", duration = 30 },

{ name = "active", duration = 180, start_condition = { type = "player_count", min = 4 } },

{ name = "overtime", duration = 60 }

}

end

function on_phase_started(phase_name, state)

if phase_name == "active" then

game.broadcast("phase", { name = "active", message = "Go!" })

end

return state

end

```

There are also entity timers for per-entity cooldowns, crafting, decay — ticked as part of the zone loop so they scale to thousands without overhead.

### Reconnection & Recovery

- Configurable grace period — player entity stays alive while disconnected

- Zone state backed up to ETS every ~1 second, recovered on process crash

- Entity persistence to PostgreSQL for node-level recovery

### Security & Production Hardening

- Per-connection rate limiting (60 msg/sec token bucket)

- WebSocket payload size limit (64KB)

- Input validation preventing handler crashes

- HTTP security headers (HSTS, X-Frame-Options, CSP, etc.)

- Chat content length limits

If anyone wants to try building something with it, the [Defold SDK](https://github.com/widgrensit/asobi-defold) is a single Lua module — happy to help get you set up.

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 15, 2026, 2:32pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/11 "2026-04-15T14:32:13Z")

</div>

I have now improved the documentation with Lua also.

> **[Asobi docs](https://asobi.dev/docs)**
>
> Open-source multiplayer game backend built on Erlang/OTP.

---

<div class="post-metadata">

**Author:** ![cenullum](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/cenullum/32/40863_2.png) [@cenullum](https://forum.defold.com/u/cenullum)\
**Post date:** [April 15, 2026, 3:02pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/12 "2026-04-15T15:02:48Z")

</div>

Does websocket have rate limit feature? How do you protect from spam?

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 15, 2026, 4:01pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/13 "2026-04-15T16:01:51Z")

</div>

Right now it is handled in Asobi.

Per-connection msessage rate limit:  
60 messages / 1000 ms  
65,536 bytes max per message

Chats have a 2000 bytes cap.

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [April 21, 2026, 9:21pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/14 "2026-04-21T21:21:34Z")

</div>

Now solved the hot-code reloading of lua files:

---

<div class="post-metadata">

**Author:** ![Daniel\_Widgren](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/daniel_widgren/32/20551_2.png) [@Daniel\_Widgren](https://forum.defold.com/u/Daniel_Widgren)\
**Post date:** [July 25, 2026, 12:56pm UTC](https://forum.defold.com/t/asobi-open-source-multiplayer-game-backend-for-defold/82612/15 "2026-07-25T12:56:41Z")

</div>

I have now started Asobi cloud if someone want to try it out. It is very early stage. I have invite now so I can manage and support people while I also do my day job.

> **[Asobi](https://asobi.dev/cloud)**
>
> Open-source multiplayer game backend built on Erlang/OTP.
