Data to store:
User Database: User data is modified relatively infrequently, but is probably read somewhat often. It is also likely well structured. A relational DB is a good fit for this case. We can use the following schema to store user data:
Posts are constantly being created, so we want storage solution that can handle alot of writes. Also, only recent posts will be read heavy, while older posts will be read much less often. Let's use a NoSQL Key-Value store to persist the posts long term, keyed by post UUID. We will discuss how to cache them for near term access later.
Friend relationships are often best represented with a NoSQL Graph database like Neo4j. We will use that solution in this design.
Incoming posts should be received, persisted to storage, then fanned out to all users following the post's author. The fanned out posts will be stored in a pre-computed news feed in a cache and fetched by the corresponding user whenever they log in or refresh their client app.
We will need:
A user posts a new tweet:
A user requests their latest newsfeed:
Some areas we can improve:
Database design: