Home  >  Article  >  Backend Development  >  How to implement segmentfault url?

How to implement segmentfault url?

WBOY
WBOYOriginal
2016-08-18 09:15:381175browse

https://segmentfault.com/a/11...
How the 1190000000490733 behind the url is implemented, and the benefits of this method

Reply content:

https://segmentfault.com/a/11...
How the 1190000000490733 behind the url is implemented, and the benefits of this method

This is the answer you want
http://segmentfault.com/q/1010000000142374

The answers below are all guesses. Any similarities are purely coincidental!

There is a service similar to the global numberer, which issues numbers according to fixed system rules

The first three digits are reserved for system module identifiers. For example, 101 is Q&A, 119 is article, notes is 133, position is 128, activity is 116, favorites is 123, etc. There may be other modules.

Then the next 13 bits are equivalent to a trillions of data reserved, and all data of all modules generated in the system are automatically incremented

The benefits are:
1. Convenient database deployment by module, sub-table, distributed, etc.
2. Convenient service-oriented architecture
3. Set a certain threshold for recursive collection of full-stack data
4. Hide the actual status of a certain module Amount of data
5. Quickly know which module this data belongs to through the first three digits of the ID
6. There should be more...

a should represent article, and your URL means viewing the article with ID 1190000000490733. This kind of ID has some randomly generated rules. The purpose is to prevent users from guessing and crawlers from catching it. If you put integers like 1, 2, 3, 4, and 5 in the back row, it will be easier for others to guess

It is very similar to a RESTful interface. Read this article on the RESTful API Design Guide to know the benefits of the RESTful specification. HTTP actions are used more rationally to make the interface clear.
As for the implementation method, just ensure that a unique ID is generated.

You can use mysql’s uuid_short function to generate uuid. Of course, sf can also customize its own rules or use PHP's function to generate uuid.

After testing it, I found that the ID is discontinuous. The guess is that it should be an id generated by an id generation service that supports sub-deployment.

<code>https://segmentfault.com/a/1190000000490733
https://segmentfault.com/q/1010000006600460</code>

Articles, questions, and comments are all estimated to use this ID generation service. Therefore, if you directly +1 an ID, you will not be able to access the data.

The reason for using this distributed id generator is

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn