# Design a notification system 

There are three main types of notifications: push, email, and SMS. They are usually 'soft' real-time, and they should support opt-outs across multiple devices per user.

Pushes are routed to Apple or Firebase notification services for iOS and Android devices, respectively. SMS works through another third-party provider to proxy to any device.

Typical send ratios of push:email:SMS are 10:5:1.

### Design

[![](https://mermaid.ink/img/pako:eNp9U9uO2jAQ_RVrnkDiFhIgRBUSF_UJKIJKlUr64CYmWCQxdZxtt4h_78QOCSzbzUMyc3xmfOwzuUAgQgYeHGLxOzhSqchy66cEnx2TLzxg670PZUjWPvwwi2uh-KGAmcz2yNA5D6jiIiWZwZFcsqe5Om6XSCsClqqS-Omn7E62VDES84SrqvmcBke2b_igAx-aJb6YFeBiputCpiVlTCmeRi2S466EpwdR8_mX3Wa97_qwYllGI5bpwsavnOWs6UO3pH0T8lQeowxr5V9Zco5R4dsjqhKvNC9FVIh7IMUiqsVMN-us0SjezaZBVpTH5gobWFlkxKRYVFJ2q91GihceGg6m5JbXpM_zVbGInxpb6NtB1SaoZE5TGr_i_WdYUMXaMM3C6kfzSbs9eTD72X5NMQ7_Z9HYWFurwcXstpepRZD4kLE0JGd8oac-mNY3mW_YE-PvrYtONHwz8d5c010yJV8JOsOkFLLsX3Z5IqMU9b6EmjapBuR5BSfiGSz8N8c3vjwR6qH4kHY3GB_ycCge1u-nwxwziHlwIkrS4PTOnUMLIslD8JTMWQsSJhNapHApOvmAv3OCc-NhGFJ58sFPr1hzpul3IZJbmRR5dATvQOMMs_wc4oUtOI0kTSpUoulMzkWeKvBsxx3pLuBd4A947b497FjjoTOy3eHAHVmDFryCN-p3nL7tjq2hMx713P7g2oK_el-rY1u9gdNzXHs4sAau417_AfX8iEM?type=png align="center")](https://mermaid.live/edit#pako:eNp9U9uO2jAQ_RVrnkDiuoEEogqJi_oEFEGlSiV9cBMTLJKYOs62FPHvndi5wLJdHsLMmTOTY5_JFXwRMHDhEInf_pFKRZZbLyH42zH5yn223ntQhGTtwQ9TXAvFDznMZLpHhs65TxUXCUkNjuSCPc3UcbtEWh6wRBXETz9ld7KlipGIx1xVw-fUP7J9wwMdeNAs8MUsBxcz3RcwLSllSvEkbJEM30p4chA1n3_Zbdb7rgcrlqY0ZKlubPzKWMaaHnQL2jchT8UxirBW_pXF5wgVvj2iKvBK81KEubgHUiTCWsx0s04bjfzZbBpkRXlkrrCBnXlGTIpNBWW32m2keOWB4WBKyrwmfZ6v8iL-1dhC3w6qNkElc5rQ6IL3n2JDFWvDNAu7H80n7fbkwexn-zXFOPyforGxtlaDi1n5LtOLIPEgZUlAzvhATz0wo0uZb9gT4285RScaLk28N9dMl0zJC0FnmJRCFvOLKU9klKLel1DTJtWCPFdwI57B3H9zfOPLE6Feig9pd4vxIQ-X4qF-vx3mmH7E_RNRkvqnd-4cWhBKHoCrZMZaEDMZ0zyFaz7JA_ycY9wbF8OAypMHXnLDnjNNvgsRl21SZOER3AONUsyyc4AXtuA0lDSuUImmMzkXWaLAtQbWUE8B9wp_wG2_WE7HGfZ61sAe2QN7OB604AKuPe7Yzos9tq3-0B5YI_vWgr_6xf2O1R_3-5blWA6WeiPn9g97Foh3)

### Production Features

To support high volumes, you'd need to use **queues**, which mostly have [at-least-once semantics](https://blog.bytebytego.com/p/at-most-once-at-least-once-exactly) and use it in conjunction with cache on the `eventId` to avoid processing repeat notifications. Monitor queued notifications for delays or failed messages in the [dead letter queue](https://aws.amazon.com/what-is/dead-letter-queue/).

Use a [rate limiter](https://blog.danwald.me/design-a-rate-limiter) to ensure you're within the bounds of the external service. 

Maintain a repository of templates to standardize messages and save user preferences allowing to toggle notification channels.

Lastly, notification analytics can be sent back to analytics services to measure user engagement, and messages should include options to unsubscribe.

Happy Hackin'!

### References

*   (At most once, at least once, exactly one - Alex Xu)\[https://blog.bytebytego.com/p/at-most-once-at-least-once-exactly\]
    
*   (Design a Rate Limiter)\[https://blog.danwald.me/design-a-rate-limiter\]
    
*   (What is a Dead-Letter Queue (DLQ\])?)\[https://aws.amazon.com/what-is/dead-letter-queue/\]

> This article is part of the [system design series](https://blog.danwald.me/series/system-design) where I am summarizing chapters from The System Design Interview: [Volume 1](https://amzn.to/499GXN3) / [Volume 2](https://amzn.to/4tXMYok) amongst other related content
