Case Studies/Messaging

Telegram

Cloud-native messaging with unlimited storage and channels

messagingcloudchannelsMTProtodistributed

Case study boundary

Use this as a learning model.

This page explains architectural patterns and constraints inspired by Telegram. It should not be read as the exact private production architecture or as a one-size-fits-all recommendation.

Evidence

Public info + inference

Learn first

Concepts behind this architecture

Overview

Telegram is a cloud-based messaging platform serving over 800 million monthly active users. Unlike WhatsApp, Telegram stores all messages in the cloud, enabling seamless multi-device access. It supports massive group chats (up to 200K members), channels with unlimited subscribers, and a rich bot platform. Its custom MTProto protocol is optimized for speed and reliability across unreliable networks.

Scale

800M+

Monthly active users

~15B

Messages per day

Millions

Concurrent connections

Full cloud history

Storage model

Requirements

Functional

  • Cloud-based messaging with full history sync
  • Channels with unlimited subscribers
  • Groups up to 200,000 members
  • Bot platform and Bot API
  • Secret chats with E2E encryption
  • File sharing up to 2GB per file

Non-Functional

  • Multi-datacenter distribution for resilience
  • Fast delivery across unreliable networks
  • Seamless sync across unlimited devices
  • Scalable fan-out for million-subscriber channels
  • High availability across geopolitical regions
  • Efficient binary protocol (MTProto)

High-Level Architecture

Loading diagram...
Telegram — High-level system architecture

Key Components

Access Points

Geographically distributed entry points that establish MTProto connections. Clients connect to the nearest access point for minimal latency.

Message Router

Core routing engine that determines the destination datacenter and server for each message. Handles both 1:1 and fan-out delivery.

Channel Service

Manages channels with potentially millions of subscribers. Uses an efficient lazy-loading approach — messages are stored once and fetched on demand.

Sync Service

Maintains a sequence of updates per user across all their devices. Each device tracks its own sync point and fetches missed updates on reconnection.

Bot API Service

HTTP-based API layer for third-party bots. Translates between the Bot API (JSON/HTTP) and internal MTProto-based communication.

Media Service

Handles upload, storage, and delivery of files up to 2GB. Files are split into parts and distributed across the storage cluster.

Data Model

Loading diagram...
Telegram — Entity relationship diagram

MTProto Protocol

Telegram uses its custom MTProto protocol, designed for speed and reliability on mobile networks.

Key Design Decisions:

  • Binary encoding: Messages use TL (Type Language) serialization, more compact than JSON/Protobuf
  • Transport flexibility: Works over TCP, HTTP, and UDP with automatic fallback
  • Encryption layers: Server-client encryption (default) and optional E2E (Secret Chats)
  • Built-in ACK: Automatic resend for lost packets

Connection Optimization:

  • Persistent TCP connections with keepalive
  • Request pipelining — multiple RPC calls over a single connection
  • Compression of large payloads using gzip
  • Quick reconnection with session resumption (no full handshake)

MTProto achieves significantly faster message delivery than HTTPS-based alternatives, especially on high-latency mobile connections.

Loading diagram...
MTProto Protocol

Multi-Datacenter Architecture

Telegram operates across multiple datacenters worldwide, with each user assigned to a “home” datacenter.

Datacenter Assignment:

  • Users are assigned to the nearest DC at registration
  • Each DC is a complete, autonomous unit with its own storage
  • User data lives in their home DC

Cross-DC Communication:

  • When User A (DC1) messages User B (DC3), the message routes through a high-speed inter-DC backbone
  • Media files may be cached in non-home DCs for faster access
  • Secret chats require both participants’ DCs to coordinate

Benefits:

  • Data sovereignty: Users’ data stays in their assigned region
  • Latency optimization: Most operations happen within a single DC
  • Resilience: DC failures are isolated
  • Regulatory compliance: Data kept in specific geographic regions

Channel Fan-Out Strategy

Channels are Telegram’s broadcast mechanism, with some having millions of subscribers. Telegram uses a read-optimized approach:

Storage Model:

  • Channel messages are stored once in the channel’s message history
  • Subscribers do NOT get individual copies (no write amplification)
  • When a subscriber opens a channel, messages are fetched from the shared store

Notification Fan-Out:

  • Only notifications (not full messages) are fanned out
  • Notifications are batched and sent in bulk
  • Muted channels skip notification delivery entirely

Read State Tracking:

  • Each subscriber has a simple pointer (last_read_msg_id) per channel
  • Unread count = latest_msg_id - last_read_msg_id
  • O(1) per subscriber, no per-user message copies

This allows channels to scale to millions of subscribers without proportional storage or write costs.

Architectural Tradeoffs

Cloud storage vs. E2E encryption by default

Pros

  • +Seamless multi-device sync
  • +Full message history search
  • +No backup hassles

Cons

  • −Server can theoretically access messages
  • −Privacy concerns
  • −Larger storage infrastructure needed

Custom MTProto vs. standard protocols

Pros

  • +Optimized for mobile networks
  • +Lower latency than HTTPS
  • +Built-in reconnection

Cons

  • −Security scrutiny from custom crypto
  • −Higher barrier for third-party clients
  • −Complex maintenance

User-DC assignment model

Pros

  • +Data locality for fast operations
  • +Simple data ownership model
  • +Geographic compliance

Cons

  • −Cross-DC messages have higher latency
  • −DC migration is complex
  • −Uneven load distribution possible

Learn From Telegram

Copy a learning context prompt for an AI assistant. It keeps assumptions visible and asks for tradeoffs, cost drivers, failure modes, and what to measure before adding complexity.

Explore More Case Studies