Skip to content

🎨 High load pixelbattle backend written in Go 🩵

License

Notifications You must be signed in to change notification settings

mrsobakin/pixelbattle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Report Card License

🎨 Pixelbattle - Backend ⚙️

Blazingly fast ⚡ and reliable 🦾 backend for the pixelbattle game.

This repository is a part of pixelbattle series - a full stack journey into creating a simple, production grade service.

📝 Protocol

  1. The client connects to the websocket endpoint. Based on its session cookie, auth server provides a user id (or says that cookie is incorrect).
  2. Server sends image of a canvas in png format to the client, as a binary message.
  3. Client and server exchange symmetric canvas update messages in JSON format: {"pos": [x, y], "color": [r, g, b]}

🤔 Interesting facts

Initially, this project was supposed to be written in Rust. However unfortunately, Rust's websocket implementation, tungstenite, didn't have the feature I needed. So this one goes to the Gophers.

For this project I had to write my own mpmc channel for broadcasting canvas changes. Maybe go already had something like it, or I could kludge something up with the go channels, but I've decided that it would be better just to write it from scratch.

Here's some info about this channel:

  • It's a multi-producer multi-consumer channel (obviously).
  • It's based on a ring buffer.
  • The buffer is shared between all consumers and producers.
  • Sending messages never fails and never blocks (unless you do simultaneous reads/writes).
  • If the consumer is lagging behind by more than the buffer size, current read failes, and consumer queue is reset to the top message in channel.
  • No messages are lost (unless consumer had lagged behind).

About

🎨 High load pixelbattle backend written in Go 🩵

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages