当前位置:网站首页>How to design a highly available and extended image storage function
How to design a highly available and extended image storage function
2022-06-24 08:10:00 【A more dreams a】
The article brief introduction
In this paper, a small e-commerce system is designed Picture storage Module analysis and summary , Share how to design a suitable image storage function .
Common image storage methods
In daily system design , It is inevitable that the picture function will be involved , For example, pictures of commodities 、 Article cover 、 User profile, etc . Create a picture field for the data in the normal way , This field stores the path of the file . As the format below :
Data number | Other fields | Picture field |
|---|---|---|
1 | ... | |
2 | ... |
There are good and bad points in the above data table design :
advantage :
- Simple storage , Users only need to upload pictures , Get a picture of url Just store it .
- Simple presentation , The client only needs to be based on the value of the field , Show it .
Inferiority :
- Weak expansibility , If we change the domain name of our pictures later , You need to replace the domain name in all the data .
- Weak multi picture scalability , If one piece of data has more than one picture , The stored value may be in this format . Picture path 1, Picture path 2,...., Picture path n. Although storage is simple , However, data format conversion is required in the presentation stage , You need to convert a string to an array format for circular processing .
- Waste storage resources , Suppose there is a picture a, I uploaded the user's Avatar once , I also uploaded the product pictures once , In this way, the same picture will be stored twice , Double the storage space .
- The first 2 Point refers to the path problem , You may think that I don't store specific domain name information in my picture , Store only the name of the picture , You can splice it when the client shows it .$domain = 'https://www.baidu.com/'; $imageArray = ['1.png', '2.png', '3.png', '4.png']; foreach ($imageArray as $value) { $domain .= $value; } The above method can avoid the domain name problem , But it is also inevitable to avoid the problem of storage mode . It is possible that qiniu cloud storage was used in the early stage of the system , The following applies to Alibaba cloud storage , Tencent cloud storage , This needs to deal with storage methods . Although it can also solve , But it makes the system design more complicated .
Optimization idea
According to the above question , We can think about it , If all the pictures of the system , All of them are made into a functional module , There's not a place that needs to involve pictures , To call the list data in this module , Get the picture of the system , Would this be better ?
Pictured above , Picture management function of wechat official account . On the left is the classification of pictures , On the right is the corresponding specific picture . Where we need to apply pictures , Go to get the corresponding picture data .
meanwhile , We also have an independent material library management , You can view all the pictures of the system , Easy to manage pictures .
The project design
The optimization idea mentioned , Let's create a separate image manager . How should we design the data sheet ? Here we will demonstrate the image management of wechat official account .
- First, we have a classification of pictures , At this time, you need a picture classification table (image_category).
- Next , We need to create a specific picture table (image), Used to store specific picture data .
- Image classification is mainly the name of classification 、 Sort 、 Creation time and other information .
- The picture information table stores more fields . With picture classification id、 Store domain name 、 The name of the picture 、 The image url、 Size of picture 、 Information such as the type of picture .
- Take a field in the table to store the domain name , When the client obtains the domain name and the name of the picture , Direct splicing is the completion path of an image .
- The size of the picture and the extension of the picture , It is convenient for us to display on the page later . Some systems may show the size of the image .
Summary of the plan
Through the design above , We can summarize the following advantages :
- Optimized image storage space , Avoid uploading the same picture multiple times , Occupy the storage space of the system .
- If different storage platforms are involved , We have a domain name field in the picture , Just splice the domain name and picture name . In the later stage, no matter how many storage platforms are changed , The system will not have any impact .
- It is convenient for the system to manage pictures , In this way, the pictures are stored independently , It is convenient to view all picture data of the system .
- Tables involving business data , You only need to associate the id that will do .
边栏推荐
- Pipeline concept of graphic technology
- These dependencies were not found: * core JS / modules / es6 array. Fill in XXX
- Vulnhub靶机:BOREDHACKERBLOG: SOCIAL NETWORK
- Timer usage notes
- 对于flex:1的详细解释,flex:1
- 第 2 篇:绘制一个窗口
- Keep one decimal place and two decimal places
- 2022 PMP project management examination agile knowledge points (1)
- Practice of opengauss database on CentOS, configuration
- 调用Feign接口时指定ip
猜你喜欢

Latest news of awtk: new usage of grid control

Chapter 3: drawing triangles

Svn actual measurement common operation record operation

JDBC 在性能测试中的应用

5-if语句(选择结构)

Moonwell Artemis is now online moonbeam network

1279_VMWare Player安装VMWare Tools时VSock安装失败解决

Case examples of corpus data processing (cases related to sentence retrieval)

慕思股份在深交所上市:毛利率持续下滑,2022年一季度营销失利

ImportError: cannot import name ‘process_pdf‘ from ‘pdfminer.pdfinterp‘错误完全解决
随机推荐
L1-019 who goes first (15 points)
The monthly salary of two years after graduation is 36K. It's not difficult to say
Using kubeconfig files to organize cluster access
C# Lambda
Cold thinking on the hot track: multiplier effect is the fundamental requirement of East West calculation
5g industrial router Gigabit high speed low delay
UTC、GMT、CST
The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain
Decltype usage introduction
Introduction to software engineering - Chapter 3 - Requirements Analysis
Saccadenet: use corner features to fine tune the two stage prediction frame | CVPR 2020
Part 2: drawing a window
宝塔面板安装php7.2安装phalcon3.3.2
These dependencies were not found: * core JS / modules / es6 array. Fill in XXX
Introduction to software engineering - Chapter 2 - feasibility study
Swift 基础 闭包/Block的使用(源码)
More than observation | Alibaba cloud observable suite officially released
快速读论文----AD-GCL:Adversarial Graph Augmentation to Improve Graph Contrastive Learning
软件工程导论——第二章——可行性研究
OC extension detects whether an app is installed on the mobile phone (source code)