a mini version of instagram
这是笔者是Gatech OMSCS项目CS6400的课程项目。
我把它deploy到aws上去,
这个链接在 2019年7月前应该都是有效的
http://52.206.247.212:8080
我在面试中的project deep dive环节用我的这个course project 过了那一轮面试。
Basic function:
- User register/login
- User Create CorkBoard(相册)
- User Add Push Pin(photo)
- User View Other people's corkBoard
- User "Watch" a CorkBoard.
- User Like PushPin
- User follow other user
- User Comments a PushPin
- Search
- Popular Sites(图片来源最多的站点), Popular tags(最热门的tag), Statistics :各种统计数据
- Generate time line
Data model
- User table
user_id, user_email, name, pin - CorkBoard table
corkboard_id, owner_id, category - Pushpin Table
id, owner_id, corkboard_id, url, tag - Watch Table
user_id, corkboard_id (user_id做为ordering field) - Like Table
user_id, pushpin_id (pushpin_id做为ordering field) - Follow Table
user_id, followee_id - Comments Table
pushpin_id, user_id, timestamp, content - Category Table
category - Tag Table
tag
选用SQL 数据库,因为主要是结构化的data,(除了照片)
SQL支持比较复杂的查询。比较容易提取出各种统计数据
图片存在单独的服务器上,本地sql数据库里只保留一个url
Working solution:
- user login in, 检查用户身份.
- Generate timeline. backend query most recent update the corkboard he watched, the people he follows. The backend merge this result and return the top k most recent update from the user.
The back end also query the user's own Corkboard and shows the statistics.
这里用到的是pull model - 用户添加数据 User add new Corkboard, add new push pin, add new comments.
- Other functionality: Search, 使用Like 语句查询join起来。
登录信息存在哪里
php里面有Session, session信息存在server端。SessionId传给浏览器,浏览器每次访问时都要带着SessionID. Server端的session信息可以存在内存里,反正也不是需要持久化。
Scale
这个项目目前是单机版
如果需要scale的话: 使用consistent hashing.
Sharding Key: user table, corkBoard table, watch,follow都按 user id sharding,
pushpin table, comments_table 按 pushpin id sharding.
如何加速查询
读多写少的系统,可以用Cache进行优化。Memchched
对于热门统计(popular tag, popular site)可以定期查询(每一小时查一次存起来)。
也可以在tag table里增加一个field 叫count, 每次有新图片被了tag 就update tag table, 这样就很方便查最热门的tag了。也可以增加一个table叫site 进行popular site查询的加速
建立索引:因为pushpin table 和comment table数据最大,先对pushpin table建立primary index, comment table建立primary index。
对Like table建立索引按 pushpin_id建立clustering index,(因为经常要显示一个图片有多少人like了)
网友评论