This is the 25th day of my participation in the August Genwen Challenge.More challenges in August

The functional requirements

  • Release dynamic: similar to the circle of friends function, support pictures, text, video.
  • Dynamic reading: supports columns such as recommendation, latest and hottest.
  • Dynamic deletion: Supports publisher deletion and operation deletion (including hard deletion and soft deletion).
  • Audit dynamic: need to have normal, audit, blocking medium.
  • Dynamic gift and Thumbs-up: Supports sending and thumbs-up to a dynamic item. And you need to send a message to the publisher. And there needs to be a list of messages that can be deleted and cleared with one click.
  • Dynamic operation: the operation can be the top, recommend a dynamic, and also release the official dynamic as the operation.

Requirements analysis and preliminary design

Considering that the release dynamic crowd is the anchor, so the amount is not very large, the design of the table does not need to be divided into tables.

Dynamic pages are frequently accessed, so use thumbnails if there are multiple images on the main page, otherwise use original images, the video shows the first frame, and the CDN does the rest.

When the interface reads the data, it pulls the dynamic ID as required and caches each dynamic metadata to speed up the interface.

For gifts and likes, consider concurrency and efficiency. Send messages asynchronously to queue for slow processing.

In terms of messaging, it provides an interface that requests when the client enters the dynamic page for the first time to get the latest message, and then the client listens for the message to draw the NEW message UI.

Database design

There is no need to elaborate on the specific details. There are roughly the following tables:

A few points to note:

  • Keep the likes and gifts in the main table, not the sum table. (Write slower, read faster)
  • Add all tablesis_delete, indicates soft deletion. Only those violating the rules can be deleted, which is convenient for operation restoration.

Code design

Generally speaking, this function is relatively simple, just an upload and query process.

Note:

  • The dynamic metadata cache, a dynamic one, if the dynamic changes directly update the cache, according to the business, generally set 3-7 days to expire.
  • Home sorting in advance with the command command calculated, different pages directly get sorted dynamic Id, and then check the cache. Home page can not cache, just take all the cache process. (The whole return value set cache, the first is to occupy redis memory, the second is to take out all the parsing and direct lookup efficiency is almost the same, the third is direct lookup real-time better.)
  • Once there is a background delete, block operation, delete a dynamic cache, when the cache generation can not read the judgmentis_deleteCan. (It is not necessary to directly execute command to calculate commands. Firstly, it may take a long time. Secondly, some algorithms are based on time, so they need to be executed regularly.)
  • If the number of likes is too high, you can consider adding a message queue, but there may be ABA problems. (Likes go up and down)

The last

The overall design is roughly like this, if you have any questions welcome to comment or private message me oh. I’ll see you next time.