Ntfy: the joys of handling 4 million push notifications per day

Abstract

ntfy is an open source push notification service that has grown from a small side project into infrastructure used by homelabbers and businesses around the world. Its free public instance, ntfy.sh, has delivered more than one billion messages over the past four years and now handles around four million push notifications every day.

In this talk, I’ll share what I’ve learned from running a free service that requires no signup: dealing with abuse, designing effective rate limits, scaling the service as usage grows, and keeping it reliable, all while keeping the project fully open source.

Speaker Bio

Philipp Heckel
Philipp C. Heckel is a software engineer, open source developer, and the founder and maintainer of ntfy. He is Chief Architect at Slide, where he works on backup and disaster recovery systems. Philipp has spent close to two decades working with Linux, distributed systems, infrastructure, and backups, and enjoys getting his hands dirty with low-level systems problems and writing Go. Originally from Germany and now living in Connecticut with his family, he has been building, operating, and writing about open source software since 2008.

3 Likes

You showed a number of examples of unique notifications ntfy can handle (e.g. Text, markdown, image). What is the feasibility of sending DOOM as a notification?

Also, apologies if that 8 million number grows by us inviting you here.. :slight_smile:

2 Likes

How do you receive a notification if Ntfy fails?

2 Likes

This is fantastic service. Did you start it as just a cool idea or was there a particular problem you wanted to solve or gap in the market?

2 Likes

What is the load balancer for the cluster and did you need any special features to mitigate the thundering herd etc?

“who load balances the load balancer?!”

^ repost from the live chat ( thank you for kind admonition @guiverc :face_with_peeking_eye::slightly_smiling_face: )

great talk ofc! thank you for pushing the boundaries of opensource and providing such an amazing service for everyone! :slight_smile:

2 Likes

Doom apparently is roughly 11 MB, so you could send ~3.6k ntfy messages, each 4 KB, to store DOOM. :slight_smile:

3 Likes

I started it when Google discontinued its Jabber/XMPP support in Google Hangouts. I had been using Google Hangouts to alert myself of failures in scripts and backup errors, and a few months later, ntfy was born.

2 Likes

“who load balances the load balancer?!”

Right now the LBs are set up as a failover mode via Route 53, so only one is handling all traffic at a time. I am very close to adding multi-LB support (multiple A/AAAA records on the ntfy.sh DNS record). Once I have that, I’ll be able to scale the LBs truly horizontally, and all I’ll have to do is monitor the LB health and take the DNS record offline if one fails.

2 Likes

Thank you for this wonderful question. I answered it live, but for the other online folks: The current LB is nginx, though I am experimenting with writing my own (freshly open sourced 1min ago: GitHub - binwiederhier/ntlb: Load balancer for ntfy: consistent sticky routing, health checks, paced drains · GitHub) that can facilitate draining connections as well, while being compatibly with all of nginx’s features, and enhancing it to give me more insight.

As for the special features to mitigate the thundering herd: This is the PR that introduced it (Drain cluster nodes on shutdown by binwiederhier · Pull Request #2095 · binwiederhier/ntfy · GitHub). It basically holds up SIGTERM for 3min and slowly kills subscribers, while simultaneously returning HTTP 503 on the v1/ready endpoint, so LBs don’t send traffic to this node. It goes like this:

  • systemctl stop ntfy
  • 0-1min: return HTTP 503 on v1/ready → LB doesn’t send new traffic
  • 1-4min: kill existing connections slowly
  • exit & systemd restarts

I did not expect you to enjoy the question so much! :slight_smile:

nginx has some facilities that might help but I couldn’t find a template config on the nfty repo to check. But the ntlb repo shows that you’re already using a rich set of nginx features! As you mentioned sticky routing I wanted to check if you are aware of the sticky learn directive for upstreams which means that you could pin a backend to a topic if it helps.

You might also petition the nginx team to move slow_start to open source :wink:

1 Like