Backend

  1. HTTP keep-alive
  2. MySQL keep-alive
    1. Connection pool
  3. Hash table implementation
    1. essentially bucketing: S -> index -> value 1. Approximate operation on an array
    2. hash function: conflict and conflict resolution 1. link list (chaining) 2. find next open one (open addressing) 1. How the next slot is determined? (Different probing approach) 3. Implement hash for a custom data-structure -> goal: avoid frequent conflict
    3. resizing (rehash) 1. Think about GC
  4. 一致性哈希 Consistent hashing
    1. Used for distributed caches -> split the hash table on different servers
    2. The simplest way is to take the hash modulo of the number of servers
    3. What happens if one of the servers crashes or becomes unavailable? Keys need to be redistributed to account for the missing server, of course
    4. our simple modulo distribution is that when the number of servers changes, most hashes modulo N will change, so most keys will need to be moved to a different server.
    5. We need a distribution scheme that does not depend directly on the number of servers, so that, when adding or removing servers, the number of keys that need to be relocated is minimized
    6. Consistent Hashing is a distributed hashing scheme that operates independently of the number of servers or objects in a distributed hash table by assigning them a position on an abstract circle, or hash ring. This allows servers and objects to scale without affecting the overall system. 1. Each object key will belong in the server whose key is closest, in a counterclockwise direction 2. What if adding/removing servers? 3. How to ensure the even-ness of assignment?
  5. 一般幂等,我会分场景去考虑,看是强校验还是弱校验,比如跟金钱相关的场景那就很关键呀,就做强校验,别不是很重要的场景做弱校验。
    1. 这个简单,一些不重要的场景,比如给谁发短信啥的,我就把这个 id+场景唯一标识作为 Redis 的 key,放到缓存里面失效时间看你场景,一定时间内的这个消息就去 Redis 判断。
    2. 一个消费者消费不就好了,我想说的是消费者是多线程的,你消息是有序的给他的,你能保证他是有序的处理的?还是一个消费成功了再发下一个稳妥 1. hash 取模
  6. Distributed transaction
    1. 大家可以想一下,你下单流程可能涉及到 10 多个环节,你下单付钱都成功了,但是你优惠券扣减失败了,积分新增失败了,前者公司会被薅羊毛,后者用户会不开心,但是这些都在不同的服务怎么保证大家都成功呢?
    2. 2-phase commit 1. Notify multiple system to lock resource, and then commit change
    3. Eventual consistency https://stackoverflow.com/questions/10078540/eventual-consistency-in-plain-english
  7. https://www.jiuzhang.com/course/77/?utm_source=sc-zhihu-lm0721 8.