Feed Flow基础设计
发布于 8 18, 2020 by ThinkCat.
<<<<<<< HEAD
Table of Contents
- 功能
- 设计
- 预估量:1000w用户
- 方案
- 基础架构
- 持久化数据
- 缓存数据
- 接口设计
- 基本原则
- 通用返回
- 账号
- Feed
- Comment
- Like =======
- 用户注册、登录
- 用户关系绑定:关注(加好友)、取关(删除好友),好友关系并非是严格的完整双向关系。
- feed流数据维护:关注下可见,取关不可见
- feed流数据可见性维护:仅限自己和好友
- 点赞、评论功能,评论均可见
- 好友聊天
- 用户账号体系统一以mobile为唯一区分
- feed推模式:feed产生后,推送到不同的用户队列下
- 推荐feed,feed_id推送到用户的redis队列中,队列保持固定大小,新的feed放到前面
- 一条feed推送时候,可以按一定的规则,推送到不同的用户下
- 读取过的feed从队列中移除,一个feed仅被浏览一次。队列变小时候,发起推送补充。
- 推荐feed,翻页查询的时候,无需偏移量,仅需要limit
- 关注feed,按focus关注关系表,关联到feed表中的account_id,查询feed(多线程并发查询,并发量与分表数相同,考虑使用countDownLatch模式)。
- 分表策略:feed表按account_id分表
- 采用redis队列维护推荐feed,队列需要保证进去过的feed,极少会再次进来(拉取后从队列中移除,触发推送补充,补充尽量随机从不同分表中获取feed,采用布隆过滤器)
- 对应1000w的用户推荐feed队列,每个队列上限1000,内存不超过4G
- 每个用户平均产生1000条feed,共100亿数据,分表256张,平均单表5000w数据量,优化索引,可以支持
- 服务器CPU,内存性能,TODO
- 持久化: mysql
- 缓存队列: redis
- 注册
=======账号
- 注册
>>>>>>> 24b6b53 ( 【init】)url:[Post] /api/account/regist
入参:
字段 类型 说明 account String password String mobile String verifyCode String type Integer Regist Type 出参: 通用返回
<<<<<<< HEAD
- 登录
=======- 登录
<<<<<<< HEAD
>>>>>>> 24b6b53 ( 【init】)url:[Post] /api/account/login
入参:
字段 类型 说明 account String password String mobile String verifyCode String type Integer Regist Type 出参: 通用返回+业务数据 T<String>: token
- 更新基本信息
=======- 更新基本信息
<<<<<<< HEAD
>>>>>>> 24b6b53 ( 【init】)url:[Post] /api/account/update
入参:
字段 类型 说明 accountId Long nickname String age String avatar String 出参: 通用返回
- 换绑手机
=======- 换绑手机
<<<<<<< HEAD
>>>>>>> 24b6b53 ( 【init】)url:[Post] /api/account/bindMobile
入参:
字段 类型 说明 accountId Long mobile String verifyCode String 出参: 通用返回
- 查询账号信息
=======<<<<<<< HEAD- 查询账号信息
>>>>>>> 24b6b53 ( 【init】)url:[Get] /api/account/{accountId}
出参:通用返回+业务数据 T (结构如下)
字段 类型 说明 accountId Long nickname String age String avatar String mobile String area String status_desc String Feed
- 发表内容
=======Feed
- 发表内容
>>>>>>> 24b6b53 ( 【init】)url: [Post] /api/feed/post
入参:
字段 类型 说明 body String files String area String topics String visibleType Integer
<<<<<<< HEAD
- 拉取内容/列表
=======<<<<<<< HEAD- 拉取内容/列表
>>>>>>> 24b6b53 ( 【init】)url: [Get] /api/feed /[list]
入参:
字段 类型 说明 type Integer offset Integer size Integer 出参:业务数据 [List]<T>
字段 类型 说明 body String files String area String topics String likeCount Integer commentCount Integer postTime Date Comment
- 拉取内容/列表
- 发表内容
- 登录
- 注册
Table of Contents
功能
=======功能
>>>>>>> 24b6b53 ( 【init】)做一个feed流项目,类似微博、朋友圈的功能,用户量预估比较小。主要有:
设计
=======设计
>>>>>>> 24b6b53 ( 【init】)预估量:1000w用户
=======预估量:1000w用户
>>>>>>> 24b6b53 ( 【init】)方案
基础架构
工具
=======方案
基础架构
工具
>>>>>>> 24b6b53 ( 【init】)持久化数据
Account
=======持久化数据
Account
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 id bigint key account varchar(50) password varchar(50) mobile char(11) unique nick_name varchar(30) default:xxx avatar text sex tinyint age tinyint area char(100) status_desc char(100) create_time datetime update_time datetime
Follow
=======Follow
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 id bigint account_id bigint follower_id bigint fans account id create_time datetime
Focus
=======Focus
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 id bigint account_id bigint focus_id bigint focus account id create_time datetime
Feed
=======Feed
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 id bigint key account_id bigint body text files text area varchar(50) topic_ids varchar(100) visible_type tinyint likeCount int commentCount int delete tinyint create_time datetime soft_del_time datetime
Feed_Comment
=======Feed_Comment
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 id bigint key feedId bigint comment text account_id bigint create_time datetime update_time datetime
Feed_Like_Account
=======Feed_Like_Account
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 id bigint key feedId bigint likeAccountId bigint create_time datetime update_time datetime
Comment_Like_Account
=======Comment_Like_Account
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 id bigint key commentId bigint likeAccountId bigint create_time datetime update_time datetime IM [TODO]
缓存数据
1.手机验证码
=======IM [TODO]
缓存数据
1.手机验证码
>>>>>>> 24b6b53 ( 【init】)key: type + mobile, value(String): verify_code
2.点赞数据
=======2.点赞数据
>>>>>>> 24b6b53 ( 【init】)key: type + feed_id, value(List): 点赞的账号id
3.用户推荐feed队列,上限1000
=======3.用户推荐feed队列,上限1000
>>>>>>> 24b6b53 ( 【init】)key:type + account_id, value(List): feed_id
4.用户在线状态
=======<<<<<<< HEAD4.用户在线状态
>>>>>>> 24b6b53 ( 【init】)key: type + account_id, 有时效性,过期则认为不在线
接口设计
基本原则
=======接口设计
基本原则
>>>>>>> 24b6b53 ( 【init】)除账户注册与登录接口,其他接口均需访问时候,在Header中增加token。
通用返回
=======通用返回
>>>>>>> 24b6b53 ( 【init】)字段 类型 说明 success Boolean code Integer errMsg String data <T> 业务数据 账号