Follow-up

Notifications

Type of notifications

  • iOS:

    • APN: A remote notification service built by Apple to push notification to iOS devices.

  • Android:

    • Firebase Cloud Messaging: Instead of APNs, FCM is commonly used to send notifications to mobile devices.

  • SMS:

    • Third party SMS providers such as Twillo, Nexmo, etc.

  • Email:

    • Set up their own email servers

    • Or commercial email service such as Sendgrid, Mailchimp, etc.

Structure

  • Provider builds notification with device token and a notification payload.

High level design

  • Notification servers could be the bottleneck

    • A single notification server means a single point of failure

    • Performance bottleneck: Processing and sending notifications can be resource intensive. For example, constructing HTML pages and waiting for responses from third party services could take time. Handling everything in one system can result in the system overload, especially during peak hours.

  • Add message queue to decouple:

    • Move the database and cache out of the notification server.

    • Introduce message queues to decouple the system components.

Additional feature: Follow and unfollow

  • Asynchronously executed

    • Follow a user: Merge users' timeline into news feed asynchronously

    • Unfollow a user: Pick out tweets from news feed asynchronously

  • Benefits:

    • Fast response to users.

  • Disadvantages:

    • Consistency. After unfollow and refreshing newsfeed, users' info still there.

Additional feature: Likes and dislikes

Schema design

  • Tweet table

ColumnsType

id

integer

userId

foreign key

content

text

createdAt

timestamp

likeNums

integer

commentNums

integer

retweetNums

integer

  • Like table

ColumnsType

id

integer

userId

foreignKey

tweetId

foreignKey

createdAt

timestamp

Denormalize

  • Select Count in Like Table where tweet id == 1

  • Denormalize:

    • Store like_numbers within Tweet Table

    • Need distributed transactions.

  • Might resulting in inconsistency, but not a big problem.

    • Could keep consistency with a background process.

Drafted overflow

Last updated