Ask HN: What is your recommended stack for real time chat?

41 points by dinkleberg ↗ HN
If you were building a new real time chat app like discord or slack in 2022, what would your tech stack look like?

I’m in this situation right now and am exploring options that will help me avoid reinventing the wheel.

My plan was to just build it from scratch using socket.io.

While looking at options like using matrix or using a third party tool like pusher, I thought to check here to see what others have done.

32 comments

[ 7.3 ms ] story [ 70.8 ms ] thread
My personal preference would be to use UnrealIRCD [1a][1b] + Anope services [2a][2b] and front-end it with TheLounge [3a][3b]. One could modify TheLounge web front-end to look just like Discord or Slack if one were so inclined. Unreal is the most flexible and stable chat daemon I have ever used. It has had decades of battle hardening and is feature rich. Most of the features are modules that can be disabled entirely.

There are more chat options here [4].

[1a] - https://www.unrealircd.org/

[1b]- https://github.com/unrealircd/unrealircd/

[2a] - https://anope.org/

[2b] - https://github.com/anope/anope/

[3a] - https://thelounge.chat/

[3b] - https://github.com/thelounge

[4] - https://www.ilmarilauhakangas.fi/irc_technology_news_from_th...

Ah, interesting. I hadn’t considered IRC at all, I’ll have to explore this.

Thanks for the suggestion!

My pleasure! If you try out Unreal don't let the configuration overwhelm you. It has evolved over a long period of time. One can find example configurations of live servers and they have a forum.
Kafka, Cassandra, Golang http server, websocket server and messsage pusher on Kubernetes
My choice, because it's the stack I know very well, would be Prosody ( https://prosody.im/ - I'm one of the devs) and a web client such as Converse.js ( https://conversejs.org/ ). XMPP is highly extensible, Prosody is highly modular, which make them a good foundation for building on top of.

That said, the right stack is generally the one that matches your requirements, and (if this isn't primarily a learning exercise) whatever you're most familiar with. The hardest part of building a Discord or Slack-like in 2022 is actually not the technical stuff. There are many comprehensive open-source products already out there that compete with these companies, such as Mattermost, RocketChat and Element.

That is an excellent point, there is a goldmine of information out there in those open source projects.

And I’ll have to take a look at prosody, I hadn’t heard of it but I did see a lot about XMPP in my research.

I'm really impressed with gunDB, which is a distributed realtime database that works in the browser.
How about NChan? https://github.com/slact/nchan

It is an nginx extension, that has supports all types of clients, channels, multiplexing, introspection, tens of thosuands connects, etc.

Elixir. That's it. There's a reason Discord and WhatsApp run on the BEAM. It does real-time with the least pain.
I wholeheartedly agree.

For a MVP, it's hard to beat Phoenix Framework channels and Liveview, and if you want to completely decouple the UI from the backend with something like a native app, or separate webapp, it's absurdly easy to just add the resources to a route that goes through the :api pipeline instead of the :browser.

Once you are ready to outgrow a single machine deployment, the BEAM clusters so well in a way that works the same on your dev machine. Also if you want to get really complicated multi-service design, Umbrella apps are leagues better than docker-compose setups that I have had on dev machines that make a 16G Macbook pro instantly put everything into swap.

> Also if you want to get really complicated multi-service design, Umbrella apps are leagues better than docker-compose setups that I have had on dev machines that make a 16G Macbook pro instantly put everything into swap.

Not sure I feel the same warm feelings about umbrella apps and I definitely don't think you can compare them to general-purpose container orchestration like docker-compose, but that's totally an optional part of the language.

Otherwise, yes, Elixir/BEAM is an excellent soft real-time environment for developing chat applications. If your scale goes off the charts (millions of concurrent users), you can extend with Rust for the slower operations in your critical path. See https://discord.com/blog/using-rust-to-scale-elixir-for-11-m...

As mentioned, Phoenix Channels is a great place to start and will get you very far. The other nice and unique things in Elixir & Phoenix (OTP, LiveView, etc.) are just a bonus.

Adding to the BEAM love; setup ejabberd, and customize to fit your needs. It's a recipe for a scalable chat setup with a small team.
You should consider just using the Matrix protocol and innovating on the UI/features side.
Honestly, rather than building it from scratch on socket.io, use any existing chat infrastructure - be that Matrix, XMPP or IRC.

My bias would be for Matrix (being project lead thereof); there is a whole new generation of client sdks (eg matrix-rust-sdk) on the horizon which are transformative - likewise massive serverside improvements like v3 sync which will provide instant login & sync (somewhat inspired by Discord). You also get e2ee, decentralisation and bridges to a bazillion other systems too.

XMPP has the additional benefit of being the IETF Internet Standard for instant messaging.
I’ll have to take a deeper look at how matrix works and dig through some of those client and server implementations.

My initial concern was that the architecture seemed at odds with what my service needs.

While I whole heartedly approve with the decentralization and E2EE approach for a general chat solution people would use like element, mine is much more niche and I need tighter control.

That being said, I haven’t dug into it enough to see how flexible it is. It would certainly save tons of effort if I could take advantage of the hard work that people no doubt smarter than me have put into this project.

would be interested to know what tighter control you are after :) there is a huge range of matrix clients these days, so you can get an idea of how much flexibility there is to build the app you need.
I love Matrix so much. It makes my heart sing.
Shameless plug, I'm co-founder and CTO of https://talkjs.com, a chat API with pre-built UIs and notifications. Our product is designed for exactly this sort of stuff.

Let me know if you want a tour! (egbert at company domain name)

Text chat? Why do you want yet another one of these? I mostly clicked the question because I thought it would be about voice or video chat, which still have some gaps in the landscape. For text chat I'm basically happy with irc.

I do think there is a missing or hard to find piece for privacy oriented friends and family chat (i.e. for just a few users, not a large userbase like discord). It would among other things have a super simple desktop client that doesn't confuse my mom. Maybe an IRC extension would suffice for the server side. Client side would be tkinter and super simple, no menus, no channels, no configuration options, just type and leave it running. I sometimes think of writing something like that.

I’m not building yet another general chat platform. I agree that there are plenty of those.

Instead, I’m building a niche socialization platform which has chat as one of its core components.

Oh I see. Well unless there are special requirements there is are probably existing modules you can drop in, e.g. from Drupal.
I would go up one level of abstraction then and look at chat-as-service / embeddable chat SDKs. If it’s a niche service, it will be a good while at best before you break even writing your own.
IRC was working great 20 years ago and it still does.
> My plan was to just build it from scratch using socket.io.

This doesn't scale, or you end up wasting all your resources on things that are not important to your customers.

Use something out there, if the business grew and you had nothing more impactful to do (building features that customers actually care about), invest on infrastructure.

as a flutter developer, I’ve been using firebase for my own apps..
I would use IRC.

While it would be acceptable to also have a web interface and/or other protocols, it should need to also display the connection information (host, port, channel) for IRC, even if JavaScripts and/or CSS are disabled.