Designing Group Chat: Fan-Out on Write vs Fan-Out on Read

How group messaging scales: fan-out on write vs read, per-member inboxes, sender keys for encrypted groups, large groups and channels, and membership changes...

Published November 27, 2026

Sending a message to one person means one delivery. Sending it to a group of 1,000 means up to 1,000 deliveries, receipts and push notifications from a single send. How and when the system copies a group message to its members, called fan-out, is the central design decision for group chat, and the same trade-off appears in social feeds, notifications and pub/sub systems.

The concept

Fan-out on write copies (or references) the message into every member's inbox at send time. Reading is cheap: each user just reads their own inbox. Writing is expensive for big groups, but group chat sizes are bounded (WhatsApp allows up to 1,024 members), so the cost is predictable. This is the common choice for chat.

Fan-out on read stores the message once in the group's timeline; each member pulls from the timelines of the groups they belong to. Writes are cheap, reads are more expensive, which suits huge audiences such as broadcast channels with millions of followers. Many real systems are hybrid: fan-out on write for normal groups and fan-out on read for very large channels.

Fan-out on write

Alice sendsone messageGroup servicelookup membersBob inboxonline → push via gatewayChen inboxonline → pushDev inboxoffline → APNs/FCM… 250 morebatched
Fan-out on write: one send becomes a delivery per member.

The trade-off

Fan-out on writeFan-out on read
Send costO(members)O(1)
Read costO(1) per user inboxO(groups joined)
StorageCopies or pointers per memberOne copy per group
Best forBounded groups (chat)Huge audiences (channels, celebrities)
Offline usersInbox ready when they returnMust merge timelines on return

Encryption changes the fan-out

With end-to-end encryption, the server cannot copy plaintext. Encrypting separately for every member would cost the sender one encryption per device. The Signal protocol's sender keys solve this: each member distributes a sender key to the group once (pairwise encrypted), then encrypts each group message once with it. The server fans out the same ciphertext to everyone. When someone leaves, keys are rotated so they cannot read future messages.

Handling membership changes

AdminGroup serviceMembersremove Devupdate membership versionsystem message: Dev leftrotate sender keysnew messages exclude Dev
Membership changes must be ordered relative to messages.

Practical examples

Fan-out worker with batching

Look up members once, group them by gateway, and send in batches.

async def fan_out(group_id, message):
    members = await groups.members(group_id)                 # cached
    sessions = await registry.lookup_many(members)           # user -> gateway or None
    by_gateway, offline = defaultdict(list), []
    for user in members:
        if user == message.sender_id:
            continue
        (by_gateway[sessions[user]] if sessions.get(user) else offline).append(user)
    for gw, users in by_gateway.items():
        await bus.publish(f"gw:{gw}", {"to": users, "msg": message})
    await push.enqueue_many(offline, message.preview)
    await inbox.append_many(members, message.id)             # for sync on reconnect

Group timeline for fan-out on read

Members pull pages after their last read sequence.

SELECT seq, sender_id, ciphertext FROM group_messages
WHERE group_id = $1 AND seq > $2
ORDER BY seq LIMIT 100;

Membership version in each message

Clients can tell which member list a message was sent under.

{ "group_id": "g-981", "seq": 5521, "membership_version": 37, "ciphertext": "..." }

Common mistakes

  • Fanning out synchronously inside the send request, so the sender waits for 1,000 deliveries.
  • Unbounded group sizes with fan-out on write, letting one message create millions of writes.
  • Not rotating encryption keys when members leave.
  • Reordering membership changes and messages, so a removed member receives a message or a new member misses one.
  • One push notification per message in very active groups instead of collapsing them.

Key takeaways

  • Fan-out on write suits bounded chat groups; fan-out on read suits huge audiences.
  • Fan out asynchronously in workers, batched by gateway.
  • Sender keys let encrypted group messages be encrypted once and fanned out as ciphertext.
  • Order membership changes with messages and rotate keys on removal.

FAQ

Why does WhatsApp limit group size?

Bounded groups keep fan-out cost, sender-key distribution and notification volume predictable. Very large audiences use separate products such as Channels or Communities.

How do social feeds use the same idea?

Twitter-style timelines fan out on write for normal accounts and fall back to fan-out on read for accounts with millions of followers.

Do group messages get one sequence or per-member sequences?

Typically one sequence per group conversation, so every member sees the same order.

More Architecture articles