Push notifications are a very popular feature for many applications.

This is how to design a scalable push notification service: ↓ {1/13}
Push notification services are usually based on a publish/subscribe model.

Clients subscribe to different information channels or topics.

When new content is available on a channel, the servers push that information out to the clients.

{2/13}
At high level a push notification service works as follow:

1. Back-end applications (on-premises or cloud) configure the service to send notifications

2. At start-up the client applications (mobile or web browser) subscribe to a topic

{3/13}
3. The service store clients contacts and information about topics, subscriptions in a database

4. The service dispatches notifications to 3rd party services

5. The 3rd party services deliver the notifications to specific platforms (IOS, Android, SMS, mail)

{4/13}
So a push notification service needs to implement these functionalities (APIs):

- create a topic
- subscribe to a topic
- publish content to a topic
- retrieve subscribed clients
- push content to specific clients

{5/13}
From non functional point of view the service needs to be:

- highly available
- durable (no content lost)
- performant to keep delivery latency low
- scalable to support many topics, publishers and clients

Those requirements can be met using multiple microservices.

{6/13}
1. Notification service

Lightweight web servers receiving requests from publishers or subscribers through a load balancer.

They interact with:

- metadata servers to send/retrieve information about topics & cilents

- temporary storage to store content before delivery

{7/13}
2. Metadata service

A service responsible for storing topics & subscriptions information in a database.

It provides 2 benefits:

- decrease the load on the db acting as a distributed cache

- implement a clear interface to access the db, increasing mantainability

{8/13}
3. Temporary storage service

A highly-available and scalable layer ensuring the content persistence.

This is necessary to implement a re-deliver mechanism in case clients are not available.

A good way to implement this layer could be using distributed message queues.

{9/13}
4. Sender service

Servers retrieving content from the temporary storage and sending it to subscribers.

The information about subscribers can be attached to the content or retrieved from the metadata service.

This last option is useful for large number of subscribers.

{10/13}
A couple of additional considerations about this design:

1. the notification servers and senders should implement a content deduplication functionality to avoid duplicated submissions and transmissions.

2. the system should ensure an at least once content delivery.

{11/13}
A common way to get this is to implement a retry mechanism.

If the temporary storage is a distributed message queue, the retry can be implemented using a queue for the undelivered content.

Alternatively such content could be put in a system monitored by subscribers.

{12/13}
Many other considerations could be done. For example:

- how to rate limit notifications

- how to make sure that only authenticated publishers send content

- how to implement a service to gather analytic data

But discussing all these would be too long in a thread.

{13/13}
Thanks for reading!

I'm Franco Fernando and I often write about distributed systems.

If you enjoyed reading this:

✓ drop a comment
✓ leave a like or retweet
✓ follow me (@franc0fernand0) for similar content

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Fernando 🇮🇹🇨🇭

Fernando 🇮🇹🇨🇭 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Franc0Fernand0

Sep 10
I recently went again through "Master the Code Review", a course by @curtiseinsmann

I got many great insights on how to get better at code reviews as both author and reviewer.

Here I share my 9 main takeaways: ↓
@curtiseinsmann 1. A code review process should fix clear expectation for authors and reviewers.

Authors should carefully prepare a description and choose reviewers familiar with the code.

Reviewers should show ownership and responsibility, being kind and thorough while writing the comments.
@curtiseinsmann 2. Reviewers needs clearly to look for flaws inside the diff like missed edge cases or possible optimizations.

But they need also to look for flaws outside the diff like:

• side effects on other part of the system
• not backwards compatible changes
• partial refactoring
Read 11 tweets
Aug 6
Microservices are not necessarily better than monoliths.

Using microservices can be a good choice or not depending on the specific use case.

The 6 main factors to take into account: ↓
1. Coupling

Microservices can be a reasonable choice only when they are loosely coupled.

Otherwise they end up being ugly not mantainable distributed monoliths.

Common reasons of coupling are poor APIs or libraries that need to be updated in lock step to multiple services.
2. Technology stack

In theory each microservice can use a different tech stack, but this has some cons.

First, having different tech stacks can be an obstacle for developers to change team.

Second, providing cross service functionalities and libraries can be more difficult.
Read 7 tweets
Jul 30
Sometimes in distributed systems a node needs to act has a leader with special powers like:

- accessing shared resources
- assigning work to other nodes
- taking care of write operations

Raft is a popular algorithm to elect a leader.

How does it work ?

//Thread// ↓ {1/9}
Electing a leader in a distributed environment is not a trivial task.

Indeed a good leader election algorithm needs to have 2 features:

1. safety: at most one leader shall be active

2. liveness: a leader shall be elected even if failures occurr

{2/9}
Raft is a leader election algorithm that guarantees these properties.

It makes 2 assumptions.

The 1st one is that time is divided into slots of arbitrary length called election terms.

Terms are numbered using logical timestamps (e.g. consecutive integers).

{3/9}
Read 10 tweets
Jul 23
HTTP servers hosts both static and dynamic resources.

HTTP caching allow to store static resources on client side bringing many benefits like:

- reduced load on the servers
- reduced response time for the users

How does client side HTTP caching works ?

//Thread// {1/9}
HTTP servers host 2 types of resources:

1. static, containing data that don't change between two different requests

2. dynamic, containing data generated by the server on the fly for each request

Since static resources don't change, they can be cached.

{2/9}
Usually the first thing that comes into mind while talking about cache is server side caching.

But HTTP protocol allows also to easily implement caching client side.

All what it's required is using some specific HTTP headers.

{3/9}
Read 10 tweets
Jul 16
An API Gateway is a reverse proxy acting as entry point in microservices architectures.

Some responsabilities of API gateways are:

- routing requests
- combine multiple APIs
- expose customized APIs

How do API Gateways accomplish this ?

//Thread// {0/9} ↓
An API Gateway is essentially a reverse proxy.

It acts as intermediary between clients and servers on behalf of the servers.

All the clients requests are received by the Gateway and not by the servers.

But the client doesn't know that it communicates with the Gateway.

{1/9}
The first task of an API Gateway is routing requests to the internal services.

Usually it uses a routing table mapping public APIs to internal APIs.

This allows internal APIs to change without breaking external clients.

{2/9}
Read 11 tweets
Jul 9
HTTP is a widely used application level protocol based on a request response paradigma.

It's main use is to encode and transport information between a client and a server.

How does HTTP works in details ?

//Thread// ↓
1. Introduction

A typical HTTP transaction is made of 2 steps:

- a client sends a request message to a server

- the server replies with a response message

Here a message is a block of text composed by multiple fields.
2. Messages

The main fields of a HTTP message are:

- the start line, indicating what a request is for or if the request was succesful

- the headers, composed by key-value pairs metadata describing the message

- the (optional) body containing the data
Read 10 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(