《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目1

设计实时股票价格查询服务
本文探讨了如何设计一个能够为最多1000个客户端提供实时股票价格查询的服务,涉及使用SQL数据库、K-V数据库或XML文件进行数据存储,并讨论了每种方式的优缺点。

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 }

 

转载于:https://www.cnblogs.com/zhuli19901106/p/3684417.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值