A TCP or WebSocket connection a device keeps open to the server. With it, the server can push a message at any time instead of waiting to be asked.
Glossary
Each idea in this book has one name in each language. Here is what each means in this book; names you will meet elsewhere follow “also”. Only terms used in published chapters are listed; each new chapter adds its own.
Basics
- long-lived connection长连接
- ACKACK(确认)
The receiver’s “got it” to the sender. In this book, the server’s ACK means the message is in the message log, not that anyone has received it.
- sync/async boundary同步与异步的分界
The line between what the sender waits for and what it does not. In this book it is the message log: the sender waits until the append, and all delivery after it is asynchronous.
- write fan-out写扩散
When a message is sent, write one entry into each recipient’s inbox; reading means reading your own inbox. More writes, fast reads; suits conversations with few members.
- read fan-out读扩散
Keep one copy in the conversation’s timeline, and each reader fetches it from there. Few writes, more reads; suits big groups.
- business layer业务层
The rules: accounts, friends, groups, permissions, moderation. It sits beside the message path: the layers call it when they need to, and messages do not flow through it.
Client
- IM SDK
The client library inside every app: the outbox and retries, sync, the local database, and the API the app uses.
- outbox发件箱
The messages on the client that have not been ACKed yet. After a disconnect or a restart, they are resent from here.
- message ID消息 ID
A unique ID the client gives each message before sending it, unchanged on resends. The server uses it to recognise a resend.
- sync cursor同步游标
One per device: how far this device has synced in its inbox. When the device comes back, it pulls everything after the cursor.
- read cursor已读游标
How far a person has read in each conversation. It lives on the server, is shared by that person’s devices, and drives unread counts and read receipts. Not the same as the sync cursor.
Connection layer
- gateway网关
A connection-layer server. Each holds many long-lived connections and handles auth, heartbeats and traffic without reading messages. One of the few stateful parts: a restart drops all its connections.
- locator接入调度
The service that tells a device which gateway to connect to. The device asks it first, then connects.
- heartbeat心跳
A small packet sent while a connection is idle. It finds connections that have died, and keeps carrier equipment from forgetting connections that stay silent too long.
Message layer (receive)
- seq序号(seq)
The number of each message in a conversation, assigned in order by the message service that owns it. It sets the order, and lets a client see which message is missing. Each inbox has a separate per-user sequence.
- dedup去重
When a message ID arrives again, return the first result instead of storing another copy. The network can only deliver at least once; dedup makes each message show once.
- sharding by conversation按会话分片
Each conversation is owned by one message service. Its seq is then assigned by a single owner, which is what keeps the order.
- message log消息日志
A durable, append-only queue: the hand-off between receiving and delivering. A message counts as received once it is in the log, and the server ACKs then. It usually runs on a message queue, such as a topic partitioned by conversation.
Dispatch layer (deliver)
- online push在线推送
A push through a gateway, over the connection, to an online device. It is a hint: if it is lost, the device catches up by pulling.
- OS push系统推送
A notification sent through Apple’s APNs, Google’s FCM or a phone maker’s channel to a phone with no live connection. A third party, best effort, with no guarantee.
- sync service同步服务
When a device pulls with its sync cursor, it returns everything after the cursor, page by page, from the inbox or the timeline.
Storage layer
- message store消息存储
The long-term history of messages, one timeline per conversation. Dispatch writes it after reading the log, so it lags the ACK a little.
- timeline时间线
All of a conversation’s messages in seq order. With read fan-out, everyone reads from here.
- inbox信箱
A per-person index of “new messages for you”, with its own per-user sequence. Write fan-out writes it, and devices pull from it by sync cursor.
- online routes在线路由表
Which gateway each online device is connected to. Gateways register devices as they connect, and dispatch looks gateways up here.