Sunday, June 28, 2015

Design复习 - careerInUS


Design复习 - careerInUS
  • 如何秒掉99%的海量数据题!!! http://blog.csdn.net/v_july_v/article/details/7382693
  • 十道海量数据题: http://blog.csdn.net/v_july_v/article/details/6279498
    • 总而言之就是hash function写到小文件,然后再处理,然后再归并
    • 注意
      • bloom filter
        • k个hash,映射到bit vector
        • 快速,节约,但有false positive且不能进行删除操作
      • hashing
      • bit-map
      • heap
      • external sort
      • trie
      • mapreduce
  • Quora关于系统设计题 http://www.quora.com/Job-Interviews/How-should-I-prepare-system-design-questions-for-Google-Facebook-Interview
  • 很有见地的一系列博文!!link
    • 重点看GFT三家的解剖!!!
    • “做大的艺术”也有对分布式的讨论
    • 缓存人气作者
  • 非常好的总结!!!link
  • facebook design 总结!!其实也是一个非常非常好的general总结 link
    • Memcache (不是memcached,那个开源的内存cache)
    • Scalable Web Architecture and Distributed Systems
      • 对于一个像flickr一样的网站,更重要的是requesting time而不是上传时间。所以优化只要集中在读的一侧而不是上传的一侧
  • flickr架构 link
  • Pinterest架构 link
  • 买买提上关于除了刷题的建议link
  • 看一下段地址的完全实现过程
  • 解剖Twitter http://blog.sina.com.cn/s/blog_46d0a3930100fai8.html
  • Google Calendar的实现过程
  • Google的系统设计题:http://www.mitbbs.com/article_t/JobHunting/32562595.html
    • 如果实现像facebook一样的activity broadcast.
    • 一个朋友f1更新一条信息后,他的所有朋友都要看到这条信息。
    • 条件:
    • 1. 朋友数量极大。
    • 2. 有的朋友在线,有的不在线,不在线的登陆后要能看到。
    • 3. 如果储存空间有限,如何处理。
  • 如何开发一个聊天室 http://book.mixu.net/node/ch3.html
  • Terasort link
    • 普通归并排序的瓶颈在于合并是是sequential的
    • Terasort保证mapper处理的各个块,i的所有元素都比i + 1的大,这样就可以自然的归并了

Keywords for Design

  • sharding (partition)
  • 非常好地区分sharding和replication!link
  • load balancer
  • master-slave replication
  • consistent hashign
  • bloom filter
  • Kafka vs RabbitMQ
    • 两个都是消息队列,message broker
  • CDN
  • peak throughput

Hired in Tech - System Design link

  • Process
    • Step 1 - Constraints and Use Cases (5 min!)
      • Very first thing to do when faced with the problem: clarify the constraints and use case.
      • Don't panic about the correctness, write some numbers down!
      • Write on board: the use cases like
        • (Basic features)
        1. take a url => return a shorter one (shortening)
        2. take a short => return the original (redirection)
        3. (ask some more augmented features?) 
        4. customized url?
        5. analytics?
        6. automatic link expiration?
        7. UI? API?
      • Write on board, constraints. Traffic and Data
        1. scale down to seconds! Estimate the traffic and data
        2. 100M new urls per month
        3. What can be cached?? 10% from shortening and 90% from redirection
        4. how long is url?
      • 都是先算几年或者几个月有多少,然后scale到秒!
      • Ready heavy? Write heavy?
    • Step 2 - Abstract Design
      • draw sketch,不要管细节!先把基础功能实现!
      • Application service layer 和 Data Storage Layer
    • Step 3 - Understand Bottlenecks
      • Need a load balancer? Data is so huge that need to distribute the database?
      • Talk about the tradeoff!!!
      • 这一步要结合1和2,比如1中的data per sec,就可以用来估算数据库是否有效?或者如果每次都要搜遍数据库的话,会不会效率过低?Bottlenecks identified!!!
    • Step 4 - Actual Design of a Scalable System!
      • (next section)
      • whenever get challenged by interviewer about the architectural choices, acknowledge that rarely an idea is perfect, and outline the advantages and disadvantages of your choice
      • add load balancer is not only for amortize traffic, but also to deal with spiky traffic!! and shut them down when the traffic goes back to normal. 
      • Don't forget to mention we need benchmark, profiling, and load test the architecture
  • Fundamentals
    • (Scalability @Harvard)
    • (Scalability for Dummies)
    • (Database sharding)
    • and don't forget about the monitor
    • sometimes there will be a flash traffic when many people want to watch/read the same thing
  • Examples
    • (highscalability blog)
  • Wrap-up
  • Practice

Scalability @Havard

  • Vertical scaling
    • CPU cores, RAM, disks, etc.
    • why not a full solution? Real-world constraints...
    • Updating drive - updating IO of databases
    • RAID
  • Horizontal scaling
    • Use more cheaper hardware, multiple servers
    • problem of CONSISTENCY, SYNCHRONIZATION
    • 用load balancer回复客户端请求,即暴露一个公共IP给外部;而所有服务器都用的内部IP,客户请求都是由load balancer来分配! 
  • Load balancing
    • Round-robin请求 to 各个服务器
    • Implement load balancer:
      • Software: HAProxy etc.
      • Hardware: 100K for decent one...
    • Use multiple load balancers to avoid single node failure at the load balancer
    • (from HiredInTech) add load balancer is not only for amortize traffic, but also to deal with spiky traffic!! and shut them down when the traffic goes back to normal. Also, when one server is down, use others (reliability)
  • Caching
    • .html - redundancy, no template, must write <header> ... lots of find and replace 
    • MySQL query cache
    • memcached 
      • memory cache, which is also a server
      • if read-heavy, then this is very efficient!
  • DB replication
    • master-slave, benefit for read-heavy websites
    • master-master, 
    • load balancer can also generate a single-node failure
    • use heat beat to detect activity
  • DB partitioning
    • different multiple servers: mit.thefacebook.com, harvard.thefacebook.com
    • A-H to server1 I-Z to server 2, etc.
  • 最后还有一段实例,很好~
    • Sync between data center?
      • load balancing on DNS level!

Scalability for Dummies link

  • part 1, replicas
  • part 2, database can become the bottleneck. Switch to NoSQL.
  • part 3, caching - in-memory caching like Redis, not file-based caching!
    • cache queries (but hard to remove)
    • cache objects, makes asynchronous processing possible
  • part 4, asynchronism
    • async 1: cache the dynamic content, pre-rendered HTML
    • async 2: (computing-intensive tasks) pass to backend, constantly check if the job is done

Database Sharding

  • 一种data partition的方式,主要用的不是replica,而是每个廉价服务器服务一部分用户
    • high availability
    • faster queries
    • more write bandwidth (parallel writing!)
    • no replica (???)

系统设计面试题思路汇总 link

  • 基本可以用Google三驾马车解决:MapReduce, GFS, BigTable
  • 三驾马车之前,常用架构是:database + sharding + cache
  • 虚拟节点技术
    • 虚拟节点技术:该技术常用于分布式数据分片中。具体应用场景是:有一大坨数据(maybe TB级或者PB级),我们需按照某个字段(key)分片存储到几十(或者更多)台机器上,同时想尽量负载均衡且容易扩展。传统的做法是:Hash(key) mod N,这种方法最大缺点是不容易扩展,即:增加或者减少机器均会导致数据全部重分布,代价忒大。于是乎,新技术诞生了,其中一种是上面提到的DHT,现在已经被很多大型系统采用,还有一种是对“Hash(key) mod N”的改进:假设我们要将数据分不到20台机器上,传统做法是hash(key) mod 20,而改进后,N取值要远大于20,比如是20000000,然后我们采用额外一张表记录每个节点存储的key的模值,比如:node1:0~1000000;node2:1000001~2000000。。。。。。这样,当添加一个新的节点时,只需将每个节点上部分数据移动给新节点,同时修改一下这个表即可
  • Q:设计一个系统,使写速度提高 -> BigTable, 并发写到一个cache里面(随机写),然后cache满了在写到磁盘(顺序写,快!)

High Scalability

  • YouTube architecture
    • Most popular content is moved to CDN
  • 8个重要的scalable design pattern link
  • What is your scalability plan link
    • 写的不错!是一步一步来的
  • 咖啡店的比喻,不错!link

公司核心技术复习

  • 必看论文
    • Google: Google File System, MapReduce, Bigtable
      • Bigtable
        • 类似于一个分布式kvs
        • key是<行,列,timestamp>
        • tablet是最小单位
    • Facebook: Cassandra
    • Amazon: Dynamo
  • 注意distributed data store
    • Non-relational, therefore quick

Google

  • Web crawling and indexes link
    • the crawler should be distributed
    • robots.txt
    • DNS resolution is a well-known bottleneck in web crawling
    • BFS的时候用优先队列,权值为key
  • DESIGN
    • 大合集!!!
    • 分布式crawler link
    • autocomplete
      • trie
      • HMM?
      • popularity
    • 读写锁
      • read write lock, 又叫share lock和exclusive lock
      • lock()和trylock()的区别:一个是blocked一个不block
      • 这篇写得不错 link
      • 两道面试题 link link
      • 注意writer starvation
      • producer comsumer link
      • mutex和cv实现semaphore link
    • distributed kv storage (DHT B+ tree)
    • distributed lock
      • 其实还是基于Paxos
    • distributed hash 
      • 分布式哈希基本介绍 link link
      • 一致性哈希 link
        • 普通线性hash缺点就在于如果移除、添加机器,需要有大量数据迁移!
      • GFS是基于metadata的实现!看!!->单点故障->一致性哈希
  • 这篇high scalability link
  • how to implement online booking link
  • 购物车 link
    • cookie和session的实现,以及与数据库的联系,讲得不错!

Facebook

  • Zuck's law
  • 这篇文章!!!!http://www.mitbbs.com/article_t/JobHunting/32741713.html
  • Hiphop compiler
Facebook Stats
Facebook Infrastructure

Facebook feeds 
  • http://readme.skplanet.com/wp-content/uploads/2012/11/0-3_Facebook1.pdf 讲得很爽
  • 系统的几个文章
    • 关于feeds的general discuss!!!!link
    • SO上的 link
    • 这里面的几个链接都非常好!!!
      • push model for people who don't have many followers
      • pull model for the other way around
Tech Talks
  • "Facebook is not about actions, but interactions"
Read full article from Design复习 - careerInUS

No comments:

Post a Comment

Labels

Review (554) System Design (293) System Design - Review (189) Java (178) Coding (75) Interview-System Design (65) Interview (60) Book Notes (59) Coding - Review (59) to-do (45) Knowledge (39) Linux (39) Interview-Java (35) Knowledge - Review (32) Database (30) Design Patterns (29) Product Architecture (28) Big Data (27) Soft Skills (27) Miscs (25) MultiThread (25) Concurrency (24) Cracking Code Interview (24) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Distributed (20) Interview Q&A (20) OOD Design (20) System Design - Practice (19) Security (17) Algorithm (15) How to Ace Interview (15) Brain Teaser (14) Google (13) Linux - Shell (13) Spark (13) Spring (13) Code Quality (12) How to (12) Interview-Database (12) Interview-Operating System (12) Redis (12) Tools (12) Architecture Principles (11) Company - LinkedIn (11) Testing (11) Resource (10) Solr (10) Amazon (9) Cache (9) Search (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Company - Uber (8) Interview - MultiThread (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Scalability (8) Cassandra (7) Git (7) Interview Corner (7) JVM (7) Java Basics (7) Machine Learning (7) NoSQL (7) C++ (6) Design (6) File System (6) Highscalability (6) How to Better (6) Kafka (6) Network (6) Restful (6) Trouble Shooting (6) CareerCup (5) Code Review (5) Company - Facebook (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Be Architect (4) Big Fata (4) C (4) Company Product Architecture (4) Data structures (4) Design Principles (4) Facebook (4) GeeksforGeeks (4) Generics (4) Google Interview (4) Hardware (4) JDK8 (4) Optimization (4) Product + Framework (4) Shopping System (4) Source Code (4) Web Service (4) node.js (4) Back-of-Envelope (3) Company - Pinterest (3) Company - Twiiter (3) Company - Twitter (3) Consistent Hash (3) GOF (3) Game Design (3) GeoHash (3) Growth (3) Guava (3) Interview-Big Data (3) Interview-Linux (3) Interview-Network (3) Java EE Patterns (3) Javarevisited (3) Map Reduce (3) Math - Probabilities (3) Performance (3) Puzzles (3) Python (3) Resource-System Desgin (3) Scala (3) UML (3) geeksquiz (3) AI (2) API Design (2) AngularJS (2) Behavior Question (2) Bugs (2) Coding Interview (2) Company - Netflix (2) Crawler (2) Cross Data Center (2) Data Structure Design (2) Database-Shard (2) Debugging (2) Docker (2) Elasticsearch (2) Garbage Collection (2) Go (2) Hadoop (2) Html (2) Interview - Soft Skills (2) Interview-Miscs (2) Interview-Web (2) JDK (2) Logging (2) POI (2) Papers (2) Programming (2) Project Practice (2) Random (2) Software Desgin (2) System Design - Feed (2) Thread Synchronization (2) Video (2) ZooKeeper (2) reddit (2) Ads (1) Advanced data structures (1) Algorithm - Review (1) Android (1) Approximate Algorithms (1) Base X (1) Bash (1) Books (1) C# (1) CSS (1) Chrome (1) Client-Side (1) Cloud (1) CodingHorror (1) Company - Yelp (1) Counter (1) DSL (1) Dead Lock (1) Difficult Puzzles (1) Distributed ALgorithm (1) Eclipse (1) Facebook Interview (1) Function Design (1) Functional (1) GoLang (1) How to Solve Problems (1) ID Generation (1) IO (1) Important (1) Internals (1) Interview - Dropbox (1) Interview - Project Experience (1) Interview Tips (1) Interview-Brain Teaser (1) Interview-How (1) Interview-Mics (1) Interview-Process (1) Jeff Dean (1) Joda (1) LeetCode - Review (1) Library (1) LinkedIn (1) LintCode (1) Mac (1) Micro-Services (1) Mini System (1) MySQL (1) Nigix (1) NonBlock (1) Process (1) Productivity (1) Program Output (1) Programcreek (1) Quora (1) RPC (1) Raft (1) RateLimiter (1) Reactive (1) Reading (1) Reading Code (1) Refactoring (1) Resource-Java (1) Resource-System Design (1) Resume (1) SQL (1) Sampling (1) Shuffle (1) Slide Window (1) Spotify (1) Stability (1) Storm (1) Summary (1) System Design - TODO (1) Tic Tac Toe (1) Time Management (1) Web Tools (1) algolist (1) corejavainterviewquestions (1) martin fowler (1) mitbbs (1)

Popular Posts