System Design | Short URL System, Website Production, Design and Construction Company

1 year ago (2024-01-25) Chief Editor
4 minutes
two hundred and twenty-three
zero

What is a short URL system?

In the Internet era, we need to access a specified resource through a URL, which may be an HTML page or an image, video, etc. After the domain name is accessed, it will be finally resolved to a specific IP and port through DNS.

However, because of the deep level of resources, the URL we may want to access is:

http : //www.zenworld.com/2022/01/01/page? id=12345

This URL is very long. If there is a short URL system at this time, we can convert it into:

http : //www.short.com/j8ve55y

See, the URL is much shorter. What are the benefits of shortening URLs

It is convenient for users to remember SMS links and other scenarios, shorten the link address to avoid occupying the length of SMS, simplify QR code links, and make mobile phones scan QR codes more accurately (less information)

Therefore, the short chain is also generally open to the outside world as a basic platform capability.

Core ideas

hash function

First, we need a hash function to map a specific URL to a unique alias. There are many ways to implement this hash function, such as the common CRC32.

F (URL)=new alias

storage

We can use relational databases, such as MySQL, to store association relationships, such as:

ID, original URL

j8ve55y,http: //www.zenworld.com/2022/01/01/page? id=12345

redirect

After the server gets the new address after processing, it returns the HTTP request, writes the status code into 302 (redirect), and writes the new URL address in the Location field of the Header.

The overall request implementation is shown in the figure:

Optimization measures

The above scheme can be used directly, and can basically achieve good performance in most scenarios after going online. However, when the amount of requests and storage continues to rise, some problems may arise that are difficult to control.

Request magnitude

Because the short chain system is the basic business system as the first link of the request, the traffic may be very high. If a large number of requests are all sent to the relational database, there may be availability problems.

The optimization measures are:

The relational database (assumed to be MySQL) enables master-slave synchronization, and the business reads from the slave database first, thus sharing a certain pressure to join the cache layer. For example, Redis can read the cache first, but cannot read the database again. If the magnitude is not large, you can directly use Redis to store+cache, which can significantly reduce the delay and achieve simple implementation

Storage magnitude

When the amount of data is large, the cost of inserting the Uuid as the MySQL primary key will become higher and higher. Because the IDs are not continuous, you need to query the page of the latest ID when inserting, and there may be a risk of page splitting. If self increasing ID is used, it can be directly inserted to the last page. Therefore, in order to optimize the insertion performance, we can use the self increasing id as the id generation algorithm.

However, the cost of performance improvement is at the expense of flexibility. For example, the business may support users to customize short chain addresses, so the Uuid mode PK ID can be directly stored as the user configured ID. Therefore, we should weigh the demands of the business and the storage magnitude as a whole whether we need to use self increasing IDs in the end.

summary

The implementation of the short connection system is not complicated. Understand the simple HTTP 302 redirection mechanism and store the URL Hash mapping results. Of course, many other business transformations may also be introduced into the business demands, such as allowing users to define addresses, timed expiration, and so on.

Finally, regarding the storage selection, I would like to suggest Redis or MySQL, which can also be used in combination. Of course, the specific use of storage depends on the positioning and magnitude of the business. We should not be divorced from the actual business in system design.

I hope it will be helpful to your work!

This article is written by: Chief Editor Published on Software Development of Little Turkey , please indicate the source for reprinting: //hongchengtech.cn/blog/4407.html
Kuke_WP editor
author

Related recommendations

1 year ago (2024-02-20)

How does the WeChat management system manage enterprise WeChat chat content, and chat records of enterprise WeChat administrator permissions

Original title: How does the WeChat management system manage enterprise WeChat chat content How does the enterprise WeChat chat content manage enterprise WeChat chat content? Most WeChat chat content viewers on the market are for private viewing, but viewing WeChat chat content in enterprises is also particularly important. Without the use of WeChat management system, many behaviors such as abusing customers, flying orders, and randomly promising customers are
six hundred and sixty-four
zero
1 year ago (2024-02-20)

Liaocheng Chiping District Sub branch of Agricultural Development Bank of China carried out the second online exercise of the new generation credit management system, and how to do a good job in credit work as a member of Agricultural Development Bank of China

Recently, Chiping District Sub branch of Agricultural Development Bank of China actively implemented the second phase online exercise of the new generation credit management system. In accordance with the requirements of the overall exercise plan issued by the superior bank, it carefully deployed, carefully organized, clearly defined the division of labor, strengthened the coordination and linkage between various departments, closely cooperated, and effectively performed various work responsibilities during the exercise. Chiping District Sub branch organized all staff of the Customer Department to participate in the online drill
four hundred and ninety-one
zero
1 year ago (2024-02-18)

Content marketing is hard to do? Zhiqu Baichuan teaches you how to easily build a content management system, and what needs to be done well in content marketing

Two days ago, we received an official email "to Baichuan to remove from the salesforce app store" - because the United States issued an administrative order on August 6, 2020, prohibiting "any WeChat related transactions", which came into effect 45 days after the administrative order was issued (that is, September 20). The "one-stop marketing cloud" provided by Zhiqu Baichuan includes
three hundred and forty-three
zero
1 year ago (2024-02-18)

Why Enterprise Content Management System?, Why did you choose Business Management

As paper has almost disappeared, your company's important documents and information need to be digitized, stored and used in a way that supports processes and workflows. Through the enterprise content management (ECM) system, you can better manage enterprise content and choose a more interactive way to process the information of the entire enterprise. Do you check the internal documents, invoices, training materials, contracts, finance
two hundred and eighty-nine
zero

comment

0 people have participated in the review

Scan code to add WeChat

contact us

WeChat: Kuzhuti
Online consultation: