返回提示词目录第 1392 页

动态信息流架构与容量规划

依据读写规模估算容量,选择信息流分发方式,给出读写链路、游标分页及边界处理方案。

完整提示词

<context>
Feeds are a classic system design trade-off. Fan-out on write (push each new item into every follower's precomputed feed) makes reads cheap but write cost scales with follower count, so one account with millions of followers stalls the pipeline. Fan-out on read (query the followed sources at read time and merge) makes writes cheap but reads expensive when users follow many sources. Most real systems use a hybrid: push for normal accounts, pull and merge for high-follower accounts, and skip precomputation for inactive users. Feeds should store item ids, not full items, and hydrate at read time so edits and deletes show correctly. Offset pagination breaks when new items arrive; use a cursor on (timestamp, id) or a ranking score plus id. Ranking adds a scoring step and makes caching harder. Small products with team-scale membership usually need nothing more than an indexed query, and precomputing is premature.
</context>

<task>
<feed>
{{feed}}
</feed>
{{#scale}}
Scale: {{scale}}
{{/scale}}
{{#stack}}
Existing stack: {{stack}}
{{/stack}}

1. Do the arithmetic first: items written per second at peak, fan-out writes per second (items times average followers), feed reads per second, and storage for precomputed feeds at the stated retention. Show the numbers and label guesses.
2. If the numbers are small, say a single indexed query (or a materialised view) is enough and stop short of a fan-out pipeline, stating the threshold that would change this.
3. Otherwise choose push, pull or hybrid. For hybrid, define the follower threshold for pull-mode accounts and how their items merge into a page.
4. Describe the write path: item persisted, event emitted, fan-out workers writing ids into per-user feed storage (for example sorted sets or a wide-column table), capped length, and skipping inactive users.
5. Describe the read path: fetch ids by cursor, merge pull-mode sources, filter blocked or deleted items, hydrate in batch, and cache.
6. Handle edge cases: deletes and privacy changes (filter at read time and clean up lazily), unfollow, backfill when someone follows a new source, edits, and rebuilding a feed from scratch.
7. If ranked, place the ranking step, what features it may use, and how pagination stays stable.
</task>

<constraints>
- Show the capacity arithmetic; do not assert that a design "scales" without numbers.
- Do not recommend a fan-out pipeline for a feed a database index can serve.
- Use cursor pagination, not offsets, for any feed that changes while users scroll.
- When a choice depends on a specific database's limits, name what to measure instead of quoting figures you are not sure of.
{{> output/uncertainty}}
</constraints>

<output_format>
## Recommendation
The fan-out model and why, in at most five lines.
## Estimates
Table of the arithmetic: writes per second, fan-out writes, reads per second, storage per day and for retention.
## Write path
Steps from new item to visible in feeds, including high-follower accounts.
## Read path
Steps to serve a page, with cursor format and hydration.
## Edge cases
Deletes, privacy changes, unfollows, edits, backfill for new follows, inactive users.
## Trade-offs
What this design costs and the trigger to revisit it.
</output_format>

可替换内容

  • {{feed}}
  • {{#scale}}
  • {{scale}}
  • {{/scale}}
  • {{#stack}}
  • {{stack}}
  • {{/stack}}
  • {{> output/uncertainty}}

分类与标签

编程开发、信息流架构、容量估算、推拉分发、游标分页、系统设计

前往 AI 图片创作