System Design of Telegram

ThinkFromSoul
6 min readDec 8, 2023

--

There are numerous cloud-based instant messaging applications available, each with its own unique features and target audience. Examples of these applications are Telegram, WhatsApp, Slack, Skype, Discord, Signal, Microsoft teams and Facebook messenger. Here we will take Telegram for system design prospective. You can explain other applications in similar manner like Telegram.

Picture of various instant messaging applications logos
Various instant messaging applications

Functional Requirements:

  1. Application type: What type of application Telegram is? (Telegram is available on mobile devices, desktops, laptops and web browser)
  2. Content Type:
  • What type of content user share on Telegram? (Telegram is used for instant text messaging between two users of Telegram.)
  • Can user share other content as well on Telegram? If yes, then what is the limit if the size of the files? (Telegram enables users to share a wide range of files, including documents, photos, videos, and audio, with up to 2GB file size per message.)
  • Can multiple users chat on Telegram? (Yes, Telegram supports large group chat and can accommodate up to 200,000 members. This feature makes it ideal for communities, organizations, and large-scale discussions.)
  • Can user broadcast the message to bigger audience? (Telegram’s channels serve as one-to-many broadcast platforms, allowing users to disseminate messages to a large audience of subscribers.)

3. Notification status: Does user get the notification of sending, receiving and delivering the messages? (Yes, Telegram messages shows it by ticks which can explain below)

  • One Tick: A single tick next to your message indicates that the message has been successfully delivered to Telegram’s servers. This means that the message has been sent to the cloud and is ready to be delivered to the recipient’s device. However, it doesn’t necessarily mean that the recipient has seen the message.
  • Two Ticks: Two ticks next to your message indicate that the message has been delivered to the recipient’s device and recipient has opened the chat containing the message. This means that the message has been displayed on the recipient’s screen, but it doesn’t necessarily mean that the recipient has read the message.
  • No Ticks: If there are no ticks next to your message, it means that the message is still pending. This could be because the recipient’s device is offline, they have network connectivity issues, or they have blocked you.

4. Audio and video calls: Can user make audio and video calls on Telegram? (Telegram offers high-quality voice and video calling capabilities, allowing users to engage in real-time conversations with individuals or groups.)

5. Privacy of messages: Does Telegram self-destructs the messages for privacy? (Telegram’s Secret Chats feature incorporates self-destructing messages, enabling users to set a timer for messages to automatically disappear after a specified duration.)

Non-Functional Requirements:

  1. Performance: Telegram should be fast. There should be minimal latency when user send and receive the messages.
  2. Scalability: Application should accommodate if user base is increasing. The performance of the application should not degrade with increased number of users or traffic.
  3. Reliability: Application should be reliable and should deliver the messages with full security and privacy.
  4. Security: Telegram should prioritize user security, safeguarding user data and protecting against unauthorized access or data breaches. Strong encryption and robust security measures should be implemented.
  5. Usability: Telegram application should be user friendly and easy to use.
  6. Internationalization: Telegram should support multiple languages and cater to users worldwide. It should be localized and adapted to different cultures and regions.
  7. Update and Maintenance: Application should be easy to maintain and update, allowing developers to fix bugs, implement new features, and address security vulnerabilities without disrupting user experience.

Scale of application:

  1. Total Users: Telegram has 250 million daily active users (DAU) as of 2023.
  2. Message Volume: Telegram process over 1 billion messages per day.
  3. Data Usage: Telegram’s data usage is estimated to be around 50 petabytes per month.
  4. Geographic Reach: Telegram has a global presence with users in over 200 countries and territories.

Use cases of Telegram:

Here we are taking two use cases of Telegram. First use case is chat between two users and second use case is group chatting.

One to one user: Telegram has multiple users and they registered in Telegram with their phone number. A user sends the message to the other recipient user. As soon as message goes, it shows one tick which means the message has been successfully delivered to Telegram server. If the recipient user is offline, then it will not deliver the message to that user. It will stay in the queue service and will wait for that recipient user to be available. We can see the last seen time stamp on the recipient user information. As soon as the recipient user will be available, then that message will be delivered on the recipient user’s device. On first user application, now the single tick will change to the double tick which means that message has been delivered to the recipient’s device and recipient has opened the chat containing the message.

Group Chat between multiple users: Telegram facilitate communication and collaboration among a vast number of participants by group chat functionality. User can engage with lots of members in real time by group chat.

High Level System Design of Telegram:

There are multiple components which make Telegram works. These components are:

  1. Devices for Telegram
  2. Load balancer
  3. Services which play an important role in Telegram functionality
  • User Service: This service stores user information and updates
  • Session Service: This service contains the session information about the users.
  • Group Service: This service stores information about the group chat users.
  • Last Seen Service: This service stores information about the status of the user whether user is online or offline.
  • Message Queue Service: It contains all the messages which user sends and stores it until the recipient user is online.
  • Push Notification Service: As soon as user get online, this service push notification on recipient device.
  • Chat Service: It stores all the messages which user share on Telegram. it contains the text messages, audio and video files.

4. Database to store information: Here we are taking microservices approach where each service has its own respective database.

High Level Diagram of Telegram

Telegram can be accessed on browser and phone devices. It goes through CDN layer where, it can handle large spikes in traffic, guaranteeing that Telegram remains responsive and reliable even during large chat volume. Traffic distributes through load balancer to the Telegram server. The microservices take the input and reach to the respective database to return the message back. It's a very high-level diagram and we are not explaining the queue service functionality in detail here.

Sequence Diagram of Telegram:

You can see the detailed flow diagram that can explain that how the message flows from server to the other user device.

Please zoom the diagram to understand the flow.

Sequence Diagram of Telegram

In conclusion Telegram’s system design is a well-designed and scalable solution for a high-volume messaging platform. Its focus on security, privacy, and user experience has contributed significantly to its success. Overall instant messages applications like WhatsApp and Telegram have become an essential part of our digital lives, transforming the way we communicate, share information, and connect with others and evolving continuously.

--

--

ThinkFromSoul

Tech Enthusiast | Data Lover | Software Developer | Cloud Enthusiast | Exploring the World of Innovation and Crafting Code