LINEの大規模リアルタイム配信基盤

LINEは毎日、何億もの利用者に即時にメッセージを届ける必要があります。グループチャット一つに数千人が参加している場合や、公式アカウントが一斉配信を行う場合など、一つの投稿が爆発的に拡散する状況も珍しくありません。本記事では、こうした即時性を支えるLINEの配信基盤を、公開資料から読み取れる範囲で概観します。
LINE must deliver messages in realtime every day to hundreds of millions of users. It is not unusual to encounter situations where a single post fans out explosively — group chats with thousands of participants, or simultaneous broadcasts from official accounts. This article gives an overview, within what can be inferred from public materials, of the delivery infrastructure that supports this realtime nature.
長時間接続を抱えるゲートウェイ
LINEクライアントは、起動中ずっとサーバーと接続を維持し、新着メッセージや通知を即座に受け取れるように設計されています。これを支えるのが、WebSocket(またはHTTP/2、独自プロトコル)を終端する専用ゲートウェイ群です。一台あたり数十万の同時接続を捌くことが要求され、一般的にはNetty/epoll等を活用したNon-blocking I/Oで実装されると考えられています。
LINE clients are designed to maintain a connection to the server throughout startup and immediately receive new messages and notifications. Supporting this is a cluster of dedicated gateways terminating WebSocket (or HTTP/2 or proprietary protocols). Each server is required to handle hundreds of thousands of simultaneous connections, and they are thought to be implemented using non-blocking I/O leveraging Netty/epoll, etc.
拡散戦略:書込時か読込時か
チャット配信の基本論点は「拡散をいつ行うか」です。Fan-out on Writeでは、メッセージ投稿時に各受信者の受信キューへ書き込みます。読み出しは速いが、巨大グループでは書込コストが爆発します。Fan-out on Readでは、グループの共通メッセージログだけ書き、クライアントが読込時に拡散します。巨大グループに強いが読込側が複雑になります。LINEはチャットの規模や種類に応じて両者を使い分けていると見られています。
The fundamental point of chat delivery is "when to perform fan-out." Fan-out on Write writes to each recipient's inbox queue at post time — reads are fast, but write cost explodes for huge groups. Fan-out on Read writes only to the shared group message log, with clients fanning out at read time — strong for huge groups but complex on the read side. LINE is seen to use both depending on the chat's size and type.
Kafkaによる非同期処理
投稿されたメッセージは、ゲートウェイから直接受信者全員に配信されるのではなく、Apache Kafkaを中継として非同期に処理されると考えられています。Kafkaは高いスループット・永続化・パーティションごとの順序保証を特徴とするため、拡散・プッシュ通知・既読管理・履歴保存など各種サブシステムへの「共通バックボーン」として適しています。LINEは長年にわたるKafkaの大規模運用実績を公表しており、内部に専門チームを置いていると語られています。
Posted messages are thought to be processed asynchronously through Apache Kafka as a relay rather than delivered directly from the gateway to all recipients. Because Kafka offers high throughput, persistence, and per-partition order guarantees, it is suited as a "common backbone" to various subsystems — fan-out, push notifications, read-receipt management, history storage, etc. LINE has published its track record of operating Kafka at scale over many years and is reportedly running it with a dedicated internal team.
Redis:オンライン状態と受信キャッシュ
「今どのユーザーがどのゲートウェイに接続しているか」という情報は、頻繁に変わるにもかかわらず、配信時に必ず参照される基本データです。これらのセッション情報や最新メッセージキャッシュは、Redis等のインメモリストアに保持されると一般的に考えられます。LINEは独自に拡張したRedis運用や、分散KVS(HBase)の長期利用を公表しており、役割に応じてストレージを組み合わせていると見られています。
Information about "which user is currently connected to which gateway" changes frequently yet must be referenced every time a message is delivered. Such session information and latest-message caches are commonly thought to be held in in-memory stores like Redis. LINE is publishing about its proprietary Redis operations extensions and long-term use of distributed KVS (HBase), and is seen to combine storage by role.
地理分散と拠点戦略
LINEは日本・韓国・台湾・タイ・インドネシアなどアジア各地で利用されており、各地域の利用者に低遅延な体験を提供するため、複数の拠点を運用していると考えられます。国境を越えるデータ転送は、各国のデータ保護規制との兼ね合いも必要になります。一般的な戦略としては、ユーザーのホーム拠点に主データを置き、他地域にはエッジキャッシュや読み取りレプリカを配置する構成が考えられます。
LINE is used across Asia — Japan, Korea, Taiwan, Thailand, Indonesia — and is thought to operate multiple datacenters to provide low-latency experiences to users in each region. Cross-border data transfer must also balance with each country's data protection regulations. A typical strategy is thought to be placing primary data in the user's home datacenter and edge caches or read-only replicas in other regions.
プッシュ通知:APNsとFCMとの連携
クライアントが切断中やバックグラウンド時には、Apple APNs(iOS)とGoogle FCM(Android)を経由したプッシュ通知が必要になります。これらの外部プロバイダは、独自の流量制限・フォーマット・再送ポリシーを持つため、LINE側でも再送キュー・失敗時のフォールバック(SMSや後追い通知)など多重の配信戦略が必要になります。
While clients are disconnected or in the background, push notifications via Apple APNs (iOS) and Google FCM (Android) are required. Because these external providers have proprietary rate limits, formats, and retry policies, LINE itself also needs multi-layer delivery strategies — retry queues, fallbacks for failures (SMS or follow-up notifications), and so on.
障害と復旧
即時配信基盤では、障害が発生してもサービスを継続できる設計が必須です。ゲートウェイクラスタは多重に冗長化され、一台が落ちた場合クライアントは自動再接続でき、Kafkaは複数ブローカーにレプリケーションし、拠点全体が障害になっても他拠点に切替できる構成が考えられます。一方、切替時には一時的な順序の逆転や重複配信など、受け入れられるトレードオフを事前に定義しておく必要があります。
Realtime delivery infrastructure must be designed to keep service running even when failures occur. Gateway clusters are made multi-redundantly so clients can automatically reconnect when one node goes down; Kafka replicates across multiple brokers; and configurations are thought to be in place to fail over to other datacenters even if an entire datacenter fails. Meanwhile, acceptable trade-offs at failover — temporary order reversals, duplicate deliveries — must be defined in advance.
帯域と圧縮
数億の接続を抱えると、心拍(keep-alive)パケット一つにもコストが掛かります。プロトコル層での圧縮(ヘッダ圧縮を含むHTTP/2や独自バイナリエンコーディング)、心拍間隔の最適化、タイプ中インジケータ・既読同期など小さなメッセージのまとめ送信など、細かい最適化の積み重ねが実サービスコストに直結します。
With hundreds of millions of connections, even a single heartbeat (keep-alive) packet has cost. The accumulation of fine-grained optimizations — protocol-layer compression (HTTP/2 with header compression or proprietary binary encodings), heartbeat-interval tuning, bundled sending of small messages like typing indicators and read-receipt sync — directly impacts overall service cost.
エンドツーエンド暗号化
LINEは「Letter Sealing」の名で一対一・グループチャットのエンドツーエンド暗号化を公表しており、配信基盤は基本的に暗号化されたペイロードを中継するだけで、内容を復号しない設計が採られています。鍵管理は複雑で、デバイス追加・履歴の再同期・グループメンバー変更など各種シナリオに対応する必要があります。
LINE has announced end-to-end encryption for one-to-one and group chats under the name "Letter Sealing," and the delivery infrastructure is designed to fundamentally just relay encrypted payloads without decrypting their contents. Key management is complex and must respond to various scenarios — device additions, history re-sync, group membership changes, etc.
おわりに
LINEの即時配信基盤は、長時間接続を抱えるゲートウェイ、Kafkaを軸とした非同期バックボーン、Redis/HBaseによるステート管理、地域分散、エンドツーエンド暗号化など、複数の層を組み合わせた巨大スタックです。「ただメッセージを届ける」という一見シンプルな要件の裏には、膨大なエンジニアリングが蓄積されていると言えるでしょう。
LINE's realtime delivery infrastructure is a giant stack combining multiple layers — gateways holding long-running connections, an asynchronous backbone centered on Kafka, state management via Redis/HBase, regional distribution, and end-to-end encryption. Vast engineering can be said to be accumulated behind the seemingly simple requirement of "just delivering a message."