【初学者】设计一个Instagram系统 system design

1. Data Model

instagram的数据应该有很多图片,以及用户的数据。因为数据比较一致,用关系型数据库mysql这种好一些。

user table

id: primary key, int, auto increasing (serial)

name: string

email: string

location: string

photo table (一对多)

id: primary key, int, auto increasing (serial)

url: string (store in S3)

caption: string

location: string

user_id: foreign key, referencing user.id

follower table (多对多)

follower_id: foreign key, referencing user.id

followee_id: foreign key, referencing user.id

2. API架构图

                                                                             Feed Generation Service

                                                                                     |                       |

                                                                                     v                      v

mobile client  -- Load Balancer -- Server (read) --> cache <--     Metadata DB

           |                                   |                                                         ^

           |                                   |---- Server (write) ------------------------|           |

           |                                                     |------------- upload --------|            |

           |                                                                                            v           |

           |------------------------------------------------------------------------     Storage S3

3. Bottleneck与初步的scale方法

1)  Load Balancer

流量很大时,将服务器server进行replica, 运用Load Balancer进行分流和routing.

2) CDN (Content Delivery Network)

数据存量大且想增加读取速度,可以按照geo location region, 按地域部署服务器 + 数据中心data center。

3) DB replica

防止数据丢失,且增加读取速度,对数据库进行备份。使用master-slave模型,write master, 更新slave, slave作为read-only的数据库。

4) cache and scalable cache

增加cache进一步减少latency. 可以schedule一个job,每隔一段时间更新cache. 以及cache可能会很大,使用scalable cache.

5) DB sharding

数据库会变大,分区切分以扩容。

你可能感兴趣的:(sql,后端,架构,数据库架构,分布式)