故事一:. .и
面试官是同胞经理,面试人不是同胞。位子是senior。
面试官:你们平时用不用cache?. check 1point3acres for more.
面试人:yeah,we use redis. not only for caching the data, I also use it for rate limiters, blah, blah.... 1point 3acres
面试官:如果哪天, for whatever reason, 不让大家用redis了,你咋办?.--
面试人:(这是啥意思?)we can use other products, like memcache, it's light weight, less built-in functions, but also a popular key-value store...... 1point3acres
面试官:(打断)no, no third party products. From 1point 3acres bbs
面试人:(他想说啥?)then we use in memory cache classes, there are also other libraries that we can use...
面试官:(打断)no, no libraries. check 1point3acres for more.
面试人:(不会吧,不会是要我写个LRU吧,刚才不是system design interview吗)Java has built-in key value store, HashMap, that we can use and expand, we can just wrap it up and enhance it.. Waral dи,
面试官:不行,我们app自己的memory都不够用了。
面试人:(哦,那还是system design)I get it. In that case, we should design our own caching service, and consider future reuse. Let's draw it on the whiteboard.
面试官:(开始点头,终于上路子了)行,让我们选个简单的写写,就LRU吧
面试人:(我靠,又改成coding了,图穷匕见啊,你耍我吧,时间还来得及吗,大哥你早讲啊)no problem, since we are running short on time, can we simplify a little and just assume the key is string, and value is generic type, and skip TTL and capacity control?
. ----
面试官:ok ok
面试人:(这里就开始手搓代码了,先写API的框架,然后解释说现成的KV store是HashMap,但是为了sort by usage时间,及时挪动,需要加一个doubly linked list,这个一定要别写边讲,或者先停下来,讲清楚为什么用了两个data structure再开始写。如果等面试官问出这个问题,就有点晚了。)
面试官:你还有几分钟,你觉得哪里不够好的可以改进?
面试人:we still have a few mins, we can add capacity control, expiration control, both are critical part. capacity control is easy to implement. how about we design a system to clean up expired data? . .и
面试官:(有两下子啊,这里写capacity容易,就是LC上有的,这家伙宁愿选难点的). 1point 3 acres
面试人:(其实我题目背的不熟,但clean up batch job最近工作里刚写过)Overall, we have two strategies, proactive cleanup and reactive cleanup. Let's only design a batch job which is a proactive clean up here. blah blah.....
也曾经面过小厂,面试官往往就是把LC上选好的题目的description原封不动直接copy一下,这种就是他们自己都没有完全理解,没有能力改动题目,改了自己可能就看不懂code了。但是必须承认,大厂面试官确实让人impress,问的问题一听就是自己都里里外外明白了,全在点子上,而且往往会对题目改动一些,这样靠记忆是过不了的。所以如果我们能预判他们的预判,提前就边写边解释清楚,这里为什么这么写,那里是为了简化才这样,就能省下时间来讨论更加重要的东西了。比如LRU写完了,还有时间,就可以自己提出来,这个cache还能怎么改进, data encryption? segregation by company id? 不一定要写出来能测试,但是能提出解决方法。