当前位置:网站首页>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 .
边栏推荐
- Common array encapsulation
- Specify IP when calling feign interface
- Interview tutorial - multi thread knowledge sorting
- 站在风暴中心:如何给飞奔中的腾讯更换引擎
- More than observation | Alibaba cloud observable suite officially released
- 解决笔记本键盘禁用失败问题
- What is the lifecycle of automated testing?
- Decltype usage introduction
- 直播回顾 | 云原生混部系统 Koordinator 架构详解(附完整PPT)
- 4-操作列表(循环结构)
猜你喜欢
From jsonpath and XPath to spl
Selenium IDE的安装以及使用
Live wire, neutral wire and ground wire. Do you know the function of these three wires?
Simple summary of lighting usage
Latest news of awtk: new usage of grid control
Configure your own free Internet domain name with ngrok
某问答社区App x-zse-96签名分析
Chapter 3: drawing triangles
开放合作,共赢未来 | 福昕鲲鹏加入金兰组织
闲谈:3AC到底发生了什么?
随机推荐
第 1 篇:搭建OpenGL环境
从 jsonpath 和 xpath 到 SPL
模型效果优化,试一下多种交叉验证的方法(系统实操)
Atguigu---15- built in instruction
Screenshot recommendation - snipaste
Auto usage example
Echart 心得 (一): 有关Y轴yAxis属性
Chapter 1 overview of canvas
5g industrial router Gigabit high speed low delay
ImportError: cannot import name ‘process_pdf‘ from ‘pdfminer.pdfinterp‘错误完全解决
Swift Extension NetworkUtil(网络监听)(源码)
Graphmae ---- quick reading of papers
[run the script framework in Django and store the data in the database]
Chrono usage notes
Decltype usage introduction
Examples of corpus data processing cases (reading multiple text files, reading multiple files specified under a folder, decoding errors, reading multiple subfolder text, batch renaming of multiple fil
第 2 篇:绘制一个窗口
SVN实测常用操作-记录操作大全
软件工程导论——第二章——可行性研究
Chapter 2 line graph of canvas