随笔- 509  文章- 0  评论- 151  阅读- 22万 

2014-04-24 00:38

题目:加入你要设计一个服务,供至多1000个client查询每日股票的最高、最低、开盘、收盘价,请描述你要如何设计这个服务。

解法:可以用SQL数据库组织,也可以用K-V数据库来提供更高性能。如果股票数量相对不大,还可以用XML文件组织数据。在百度里搜“BIDU”,或在Google里搜“GOOG”,就能看见例子了。

代码:

复制代码
 1 // 10.1 Suppose you're to design the backend part of a system, which provides queries of real-time stock prices. How would you do it?
 2 // Answer:
 3 //    Go and search "GOOG" on Google or Baidu, you'll get the real-time stock price of Google. The data transferring is best done with AJAX to the frontend, which can greatly save the amount of data transferred.
 4 //    As for the backend part, you have to use some techniques to store the data:
 5 //        1. SQL database, easy for various kinds of structured queries. You won't expose the direct SQL API to external users because it is not safe. Write a wrapper with the web programming language.
 6 //            Strength: Ability to provide more information than you expected.
 7 //            Weakness: Not so agile, if the data structure changes. Altering a SQL table is always expensive.
 8 //        2. XML files, a good way to store structured data. Good performance when the data scale is small or medium.
 9 //            Strength: Agile, easy to modify the schema. Regenerating the XML file is usually easy with script languages such as python.
10 //            Weakness: Not suitable for large data scale, as you have to parse everything in the XML only to find an item inside.
11 //        3. No-SQL database
12 //            Strength: suitable for large scale, high concurrency, flexible with data schema changes.
13 //            Weakness: Don't know yet, maybe more space usage.
14 int main()
15 {
16     return 0;
17 }
复制代码

 

 posted on   zhuli19901106  阅读(186)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示