1

I'm implementing a chat app, which will support both one-on-one conversation and Group conversations.

So far the direction was to use Redis Pub/Sub with PostgreSQL as the cold storage, and WebSocket being the transport. Every user will fetch the history from postgresql upon launch (up until the timestamp of the WebSocket+redis connection), and then subscribe to channels that go by their own user_id.

However, having a roundtrip to a DMBS with each new message sounds a bit strange, while definitely doable and legit. So I decided to examine other approaches. One possible approach was to use Kafka and eliminate the need for an DBMS altogether. It sounds viable and comes with its own set of advantages.

But turns out there's a new kid on the block - Redis Streams.

From what I gather, it is actually quite similar to Kafka in this specific scenario (chat). It has many nice features that sound very convenient for implementing a chat system.

And now I am trying to understand whether Streams + disk persistency is the wise way to go versus Kafka versus PostgreSQL+Redis pub/sub

The main aspects in consideration are:

  1. Performance. Postgres and Kafka both operate on disk, meaning slower than the in-memory operations in the case of redis. On the other hand , obviously the messages must be persisted and available at all times and events, so redis will be persisted to disk. Wouldn't that negate the whole in-memory performance gain? And even if not - would the performance gain under peak load and a big data base be noticeable?
  2. Memory / Costs. With redis these two are closely tied together. As a small startup, the efforts are focused on being ready to cope with sudden scale peaks (up to a million users), but at the same time - the costs should be minimized. Is storing millions of messages in Streams going to be too memory-costly which in turn will translate to financially-costly?
  3. Recovery, Reliability & Availability, Persistency. with Postgres, even a single instance can handle a big traffic load, but it can also offer master-slave setups and also consistency. Can Redis be a match to that? Also, with a DMBS I can be assured that the data is there to stay. Can I know that with redis?
  4. Scaling.
BVtp
  • 2,090
  • 2
  • 21
  • 50

0 Answers0