News for hackers. Stuff that matters.
Re:System design hack: Postgres is a great pub/sub and job s... by Iv on Friday November 08, 2019 @09:38PM (#21489192)
I'll soon have to do a pub/sub for an application that's close to a multiplayer video game.

Most advices I have seen say that I'll probably want to code it myself, but I was wondering about the latency of that solution? I'll likely have a SQL store and that would be a good argument to use postgres...

Re:System design hack: Postgres is a great pub/sub and job s... by kiwicopple on Friday November 08, 2019 @10:21PM (#21489353)
For straight up pub/sub (without the job server), I tried NOTIFY/SUBSCRIBE in Postgresql, but hit some limitations.

We have switched to an Phoenix (elixir) server which listens to the database, then clients subscribe via websockets. We're opensourcing it here: https://github.com/supabase/realtime

It's still in very early stages (although I am using it in production). Basically the Phoenix server listens to PostgreSQL's replication functionality and converts the byte stream into JSON, which it then broadcasts over websockets. This is great since you can scale the Phoenix servers without any additional load on your DB. Also it doesn't require wal2json (a Postgres extension). The beauty of listening to the replication functionality is that you can make changes to your database from anywhere - your api, directly in the DB, via a console etc - and you will still receive the changes via Phoenix.

Re:System design hack: Postgres is a great pub/sub and job s... by enoex1 on Friday November 08, 2019 @10:55PM (#21489470)
Redis pub / sub has worked fantastically for me - reached 100k+ concurrent users with ~80 msg / sec, but benchmarked much higher. It was the easiest, fastest, and most reliable solution I found (about ~4 years ago)
Re:System design hack: Postgres is a great pub/sub and job s... by NicoJuicy on Monday November 11, 2019 @12:01PM (#21506435)
Perhaps checkout Nats, I'm very satisfied with it ( did pretty extensive research on finding a good message system)

It's similar to Apache Kafka but very light on resources and easy to selfhost.

Ow yeah, the throughput is around 150 k msg/s. Without much configuration.

Re:System design hack: Postgres is a great pub/sub and job s... by codesushi42 on Friday November 08, 2019 @09:40PM (#21489200)
Use Redis pubsub instead.
Re:System design hack: Postgres is a great pub/sub and job s... by Iv on Saturday November 09, 2019 @12:26PM (#21492779)
Looking into it, it seems to have something like 2ms of latency which is good. Do you think it would be a good idea to use for exchanging, say, realtime position of players in a virtual world?
Re:System design hack: Postgres is a great pub/sub and job s... by codesushi42 on Sunday November 10, 2019 @03:20AM (#21497069)
Not with pubsub. You could use it as shared memory store for player states though, I guess.