avatarJIN

Summary

Telegram's cloud-based messaging platform offers a decentralized architecture with end-to-end encryption and various features, differing from WhatsApp in terms of encryption protocols, open API availability, cloud storage, and user base.

Abstract

Telegram is a popular instant messaging application launched in 2013. It provides a cloud-based messaging platform with end-to-end encryption for user communication. Telegram's system architecture is designed for high performance, scalability, and reliability, based on a client-server model. Unlike WhatsApp, Telegram uses a decentralized architecture, its own MTProto Protocol for end-to-end encryption, offers an open API for custom applications and integrations, and provides cloud storage for user data. Telegram has over 500 million active users, which is smaller than WhatsApp's 2 billion active users but provides greater privacy and security for its users.

Opinions

  • Telegram's decentralized architecture provides increased security and privacy compared to WhatsApp's centralized architecture, but may result in slower performance and inconsistency across different devices.
  • Telegram's MTProto Protocol for end-to-end encryption provides strong security and privacy features, but has been criticized for its lack of transparency.
  • Telegram's open API allows developers to build custom applications and integrations with the Telegram platform, which is not available in WhatsApp.
  • Telegram's cloud storage for user data enables users to access their data from multiple devices and provides a backup in case the user’s device is lost or damaged.
  • Telegram's smaller user base compared to WhatsApp provides greater privacy and security for its users.
  • Telegram supports a wide range of file formats for photos, videos, audio, documents, and archives.
  • Telegram offers various features such as voice and video calls, custom themes and app design, and automatic message translation between different languages.
Photo by Adem AY on Unsplash

Telegram System Architecture

Design and Components of Telegram’s Cloud-Based Messaging Platform

Thank you for being a part of this journey with me, and I hope to continue providing value to you for years to come! Giving tips by supporting me.

Hello friend, I hope you’re doing well! I’m writing to you today because I am truly passionate about sharing my knowledge and helping others learn. If you’ve found my articles to be valuable and they’ve made a positive impact on your life, I would be overjoyed if you could support me as a referred member. Your support not only helps me financially but also motivates me to continue creating content that makes a difference in people’s lives. Thank you from the bottom of my heart for considering supporting me. It means the world to me to have your support on this journey.

Telegram is one of the popular instant messaging applications that provides reliable communication services to millions of users worldwide. It was launched in 2013. It is a cloud-based messaging platform that offers end-to-end encryption for user communication. Telegram’s system architecture is designed to provide high performance, scalability, and reliability. It is a distributed system that consists of multiple components and services, including servers, data centers, and clients. The architecture is based on a client-server model, where clients communicate with servers to send and receive messages and other types of data.

For more information on messaging application-related topics, be sure to check out my previous articles.

Key Differences Between the System Architectures of WhatsApp and Telegram

  1. Centralized vs. Decentralized Architecture — WhatsApp is a centralized messaging application. Telegram is a decentralized architecture. WhatsApp stores all user data on the company’s servers to provide a seamless and consistent user experience. WhatsApp has complete control over user data. Telegram distributes user data across a network of servers located in different data centers around the world which provides increased security and privacy but leads to slower performance and inconsistency across different devices.
  2. Encryption Protocols — WhatsApp uses the Signal Private Messenger Protocol for end-to-end encryption of user communication. It can provide strong security and privacy features, including message encryption, integrity, and authenticity. Also, it provides forward secrecy. Even if an attacker were to obtain the encryption key for a specific message, they would not be able to use that key to decrypt any previous or future messages sent between the same parties. Telegram uses its own MTProto Protocol for end-to-end encryption of user communication. It provides strong security and privacy features, including message encryption, integrity, and authenticity. It also provides the ability to send large files and the option to set messages to self-destruct after a certain period of time. It has been audited by third-party security experts and has been criticized for its lack of transparency.
  3. Open API Availability — WhatsApp does not provide an open API and restricts the use of its platform to its client applications. Telegram provides an open API that allows developers to build custom applications and integrations with the Telegram platform such as building bots, games, and other interactive services.
  4. Cloud Storage —WhatsApp does not provide cloud storage and stores user data only on the user’s device and the company’s servers. If the device is lost or damaged, the user may lose their data permanently, unless they have made a manual backup of their data. Telegram provides cloud storage for user data, including messages, photos, videos, and other files. It allows users to access their data from multiple devices with an internet connection and provides a backup in case the user’s device is lost or damaged. It allows users to selectively delete messages and data from the cloud, giving users greater control over their data privacy.
  5. User Base — WhatsApp has over 2 billion active users worldwide. This large user base provides greater network effects for users. Telegram has over 500 million active users. This smaller user base provides greater privacy and security for its users.

Functional Requirements

  • Must-have
  1. Allow users to register and authenticate themselves using their mobile phone numbers or other verification methods
  2. Allow users to send text, photos, and videos
  3. Only the sender and the recipient of a message can access the content
  4. Allow users to access their account from different devices without the need for manual login every time
  5. Offer passcode lock to restrict access to the app
  6. Allows users to create and participate in group chats with up to 200,000 members
  7. Support third-party bots and integrations
  8. Provide two-factor authentication
  9. Allow users to forward messages from one chat to another or to multiple chats
  10. Provides a search bar that allows users to search for specific messages or chats
  11. Allow users to delete messages for both themselves and the recipient
  12. Allow users to send and receive money through integrated payment services, such as Stripe and PayPal
  13. Users can use Telegram on their desktop and web browsers
  14. Allow users to send other types of media up to a maximum file size of 2GB
  15. Allow users to share files of different formats and sizes
  16. Support for self-destructing messages after a certain period of time
  17. Support secret chats
  18. Edit sent messages
  19. Allow users to create and join channels
  20. Share their contact information with their contacts, including their phone number, username, and profile picture
  21. Block users, and contacts and report spam
  22. Provide the option to backup chats to the cloud and restore
  • Nice-to-have
  1. Support a wide range of file formats for photos, videos, and other media types Photos: JPEG, PNG, BMP, TIFF, WEBP, HEIF Videos: MP4, MOV, AVI, WMV Audio: MP3, AAC, OGG, FLAC Documents: PDF, DOCX, PPTX, XLSX Archives: ZIP, RAR, TAR
  2. Allow users to make voice and video calls with other Telegram users
  3. Allow users to create custom themes and app design.
  4. Allow users to mute notifications for specific chats or groups to avoid being disturbed by frequent messages
  5. Share live location updates with contacts
  6. Screen sharing during video calls
  7. Support for automatic message translation between different languages
  8. Create and manage events or reminders within the app
  9. Offer location sharing
  10. Allow users to archive chats
  11. Supports sending voice messages and stickers
  12. Support for multiple languages
  13. Telegram Passport is used to provide secure identity verification
  14. Support for integration such as In-App games and quizzes
  15. Supports polls and quizzes in groups and channels
  16. Pin important chats to the top of their chat list for quick access
  17. Shows the status of messages, such as if they have been delivered or read by the recipient
  18. Allow users to change their profile picture and status
  19. Show users their chat and call history
  20. Clear their chat history
  21. Show users which of their contacts are using Telegram
  22. Schedule messages to be sent at a later time or date
  23. Send and receive voice and video messages in secret chats
  24. Allow users to send and receive contacts or vCards
  25. Allow users to send and receive encrypted files and messages via a peer-to-peer (P2P) connection
  26. Set custom notification sounds for specific chats or groups to distinguish them from notifications
  27. Use Telegram on smartwatches through supported apps such as WatchChat
  28. Use Telegram on feature phones through supported apps such as Telegram Lite
  29. Make audio and video calls with non-Telegram users, such as phone numbers or other messaging apps

Non-Functional Requirements

  1. Reliable
  2. Low latency
  3. High throughput
  4. Security
  5. Scalability
  6. Availability
  7. Compatibility
  8. Usability

System Architecture Components

Profile Database

  • Store and retrieve user profile information, such as username, display name, bio, profile picture, and contact information
  • Allow users to update their profile information
  • Support for searching and filtering user profiles

Profile Service

  • Manage user profiles and handle user authentication and authorization
  • Provide APIs for creating, updating, and deleting user profiles
  • Integrate with the Profile Database to store and retrieve user profile information

Chat Server

  • Handle incoming and outgoing messages for individual chats and group chats
  • Provide APIs for sending and receiving messages
  • Support real-time message delivery and synchronization across multiple devices

Mapping Database

  • Store mapping between user IDs and device IDs
  • Enable users to receive messages on multiple devices
  • Allow users to link multiple phone numbers to their account

Group Service

  • Manage group chats and provide APIs for creating, updating, and deleting group chats
  • Allow group admins to manage members and permissions within a group
  • Support for group chat features such as mentions, polls, and pinned messages

Last Seen Service

  • Keep track of the last time a user was active on the app
  • Display the last-seen status of users to their contacts
  • Allow users to control who can see their last-seen status

Message Storage Server & Store Temp Message DB

  • Store and manage messages sent and received by users
  • Provide APIs for retrieving message history and searching for specific messages
  • Support for message archiving and deletion
  • Store temporary messages that are awaiting delivery or have not yet been received by the recipient

Message Type Message

  • Support for multiple types of messages, such as text, images, videos, audio, documents, and stickers
  • Enable users to send and receive messages in different formats and sizes
  • Provide APIs for processing and displaying different message types

User Analytics Service

  • Collect and analyze user data to provide insights into user behavior and usage patterns
  • Track metrics such as user engagement, retention, and growth
  • Provide dashboards and reports to help developers and stakeholders understand user activity and trends

Notification Service

  • Send push notifications to users for new messages, calls, or other events
  • Allow users to customize their notification settings, including muting or disabling notifications for specific chats or groups
  • Integrate with the chat server to deliver notifications in real-time

Bot Service

  • Enable developers to create and deploy bots that can interact with users and automate tasks within the app
  • Provide APIs for creating, updating, and deleting bots
  • Support for bot features such as natural language processing, AI, and machine learning

Payment Service

  • Integrate with payment providers to enable users to send and receive payments through the app
  • Support for different payment methods and currencies
  • Provide APIs for processing payments and managing payment history

Security Service

  • Provide security features such as two-factor authentication, passcode lock, and end-to-end encryption
  • Manage user data privacy and compliance with data protection regulations
  • Detect and prevent fraudulent activity, spam, and abuse within the app
  • Monitor for security vulnerabilities and implement measures to protect against them

Localization Service

  • Support for multiple languages and localization of the app interface
  • Allow users to switch between different languages and localize content based on user preferences and location
  • Provide tools for developers to create and manage translations and language resources

Media Compression and Optimization Service

  • Optimize media files for faster upload and download speeds and reduced storage space
  • Compress and resize images and videos to reduce file size without compromising quality
  • Provide APIs for processing media files on the server side before they are sent or received by users.

Voice Over IP (VoIP) Service

  • Allows users to make voice calls over the internet with end-to-end encryption for security.
  • Supports real-time voice and video calls and group voice chats.

Secret Chat Service

  • Offers end-to-end encrypted messaging that is not stored on Telegram’s servers.
  • Messages are only visible to the sender and recipient and are automatically deleted from both devices once they have been read.
  • Supports self-destructing messages and device-specific message deletion.
Image Credit: Code Telegram

File Storage Service

  • Provides cloud-based file storage service with granular permissions and access control to manage who can view, edit, or delete files.
  • Includes collaborative features such as commenting and version control.

Bot Analytics Service

  • Provides insights into bot usage and engagement for bot developers.
  • Includes metrics such as user activity, message delivery, and user retention to optimize bots for better performance and engagement.

In-App Browser

  • Allows users to view web pages and links within the Telegram app with support for features such as bookmarks, history, and tab management.
  • Includes privacy features such as ad blocking and tracking protection.

The High-level System Architecture Diagram

Image Credit: Creative Commons Attribution 3.0

Front-end

  • iOS: Objective-C and partly Swift
  • Android: Java
  • Windows Phone: C#
  • TDesktop: C++
  • Telegram Web: JavaScript and Node.js
  • Mac App: Objective-C

Back-end

  • Not publicly disclosed, but they likely involve a combination of programming languages and tools for handling messaging, storage, security, and other services.

References

If you’ve found any of my articles helpful or useful then please consider throwing a coffee my way to help support my work or give me patronage😊, by using

Patreon

Ko-fi.com

buymeacoffee

Last but not least, if you are not a Medium Member yet and plan to become one, I kindly ask you to do so using the following link. I will receive a portion of your membership fee at no additional cost to you.

Telegram
Instant Messaging
System Design Interview
System Architecture
System
Recommended from ReadMedium