面试先闲聊高流量系统经验。分享屏幕,显示完整英文问题:
"Roblox has a marketplace with millions of items for sale. For each item, users can choose to flag it as a favorite (similar to Like or Bookmark). An item which is flagged can be un-flagged.
Design a system which is able to show the number of favorites each item has.
User Stories:
- As a user, I want to know if this item is flagged as a favorite for me (1M qps)
- As a user, I want to flag/unflag this item as a favorite (100k qps)
- As a user, I want to see the count of all users who had flagged this as a favorite (1M qps)
Extra:
- As a user, I want to see the list of items that I have favorited. (50k qps)"
面试流程: 先要高层次设计。在共享白板上画:读密集,用 Redis 缓存计数和用户标记,DynamoDB 持久存储,Kafka 异步写处理 100k QPS 更新。
挑战:“为什么不用 item 表单计数?”解释热点问题——热门 item 会过载分片。对于 is_favorited(1M QPS),建议 Redis hash 每用户-item 对,延迟 <10ms 通过集群。
flag/unflag:用 Redis Lua 脚本幂等操作防重复计数,然后入队到 DB。
item 计数(1M QPS):Redis 缓存,写后失效,但接受最终一致性(社交功能 5-10s 延迟可)。
用户收藏列表:DynamoDB 倒排索引(user_id 分区键,item_id 排序键),分页查询限行。处理爆火 item 用限流和 item_id 哈希分片。
深入:Redis 优于 Memcached 支持原子操作;Bloom filter 用于快速 is_favorited 检查;MQ 幂等用唯一事件 ID;缓存:TTL + 哨兵防雪崩;分片:item_id 一致哈希,user_id 范围。
结尾问题:“瓶颈?”Redis 网络 I/O 于 1M QPS。“10 倍 QPS?”加副本,CDN 静态。“优化?”监控热键,预热缓存。
避开陷阱: 无 naive DB 计数;讨论一致性权衡;避 Redis Set 存列表(内存爆)。
心得: 重点缓存、一致性、可扩展——追问真实流量峰值,感觉真实。
如果你也在冲Roblox/FAANG,欢迎加入 CSOAHelp 题库群或预约 1v1 mock——我们有最新真题更新、澄清模板、代码优化指导。扫码/官网 csoahelp.com 咨询,助你高效通过!加油~
我们也有代面试,面试辅助,OA代写等服务助您早日上岸~

