Three things you should never put in your database

本文深入探讨了在系统设计中常见的错误决策,特别是在存储文件、使用数据库作为日志存储以及处理短暂数据时的不当做法。通过分析这些问题,提出了更有效的替代方案和技术选择,旨在提高系统的可维护性和性能。

As I've said in a few talks, the best way to improve your systems is by first not doing "dumb things". I don't mean you or your development staff is "dumb", it's easy to overlook the implications of these types of decisions and not realize how bad they are for maintainability let alone scaling. As a consultant I see this stuff all of the time and I have yet to ever see it work out well for anyone.


Images, files, and binary data
Your database supports BLOBs so it must be a good idea to shove your files in there right? No it isn't! Hell it isn't even very convenient to use with many DB language bindings.


There are a few of problems with storing files in your database:


read/write to a DB is always slower than a filesystem
your DB backups grow to be huge and more time consuming
access to the files now requires going through your app and DB layers
The last two are the real killers. Storing your thumbnail images in your database? Great now you can't use nginx or another lightweight web server to serve them up.


Do yourself a favor and store a simple relative path to your files on disk in the database or use something like S3 or any CDN instead.


Ephemeral data
Usage statistics, metrics, GPS locations, session data anything that is only useful to you for a short period of time or frequently changes. If you find yourself DELETEing an hour, day, or weeks worth of some table with a cron job, you're using the wrong tool for the job.


Use redis, statsd/graphite, Riak anything else that is better suited to that type of work load. The same advice goes for aggregations of ephemeral data that doesn't live for very long.


Sure it's possible to use a backhoe to plant some tomatoes in the garden, but it's far faster to grab the shovel in the garage than schedule time with a backhoe and have it arrive at your place and dig. Use the right tool(s) for the job at hand.


Logs
This one seems ok on the surface and the "I might need to use a complex query on them at some point in the future" argument seems to win people over. Storing your logs in a database isn't a HORRIBLE idea, but storing them in the same database as your other production data is.


Maybe you're conservative with your logging and only emit one log line per web request normally. That is still generating a log INSERT for every action on your site that is competing for resources that your users could be using. Turn up your logging to a verbose or debug level and watch your production database catch on fire!


Instead use something like Splunk, Loggly or plain old rotating flat files for your logs. The few times you need to inspect them in odd ways, even to the point of having to write a bit of code to find your answers, is easily outweighed by the constant resources it puts on your system.


But wait, you're a unique snowflake and your problem is SO different that it's ok for you to do one of these three. No you aren't and no it really isn't. Trust me.


原文:点击打开链接

撰写感谢信是一种表达感激之情的有效方式。以下是三种不同类型的感谢信写作方法: 对于工作面试后的感谢信: 写一封简洁明了的信件,重申对职位的兴趣,并感谢面试官的时间和考虑。提及面试中讨论的关键点以显示兴趣和理解。 ``` Dear [Interviewer's Name], Thank you for taking the time to meet with me yesterday regarding the [Position] role at [Company]. It was a pleasure learning more about the position and your team. I am excited about the opportunity to contribute to [specific aspect of the company or team]. Please feel free to contact me if any further information is needed. I look forward to hearing from you soon. Sincerely, [Your Name] ``` 针对收到礼物的感谢信: 在信中具体提到礼物并表达感激。分享礼物如何被使用或欣赏,让对方知道他们的礼物对你产生了积极影响。 ``` Dear [Sender's Name], I wanted to take a moment to thank you for the wonderful [Gift]. It was such a thoughtful present, and I truly appreciate the effort you put into selecting it. The [Gift] will be put to great use, and I am thrilled to have it. Thank you again for your kindness. Warm regards, [Your Name] ``` 给朋友或家人的感谢信: 这种信可以更加个性化和情感化。描述他们对你生活的具体帮助或影响,强调你们之间的关系以及你对他们深深的感激。 ``` Dear [Friend/Family Member's Name], I can't tell you how much your support means to me during this time. Your kindness and understanding have been a source of strength that I deeply cherish. Knowing that I have someone like you in my life makes all the difference. Thank you for always being there when I need you most. With love, [Your Name] ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值