In this chapter, we will tackle an interesting and classic system design interview question: designing a URL shortening service like tinyurl. 在本章中,我们将解决一个有趣而经典的系统设计面试问题: 设计一个像tinyurl这样的URL缩短服务。
In this chapter, you are asked to design a unique ID generator in distributed systems. Your first thought might be to use a primary key with the auto_increment attribute in a traditional database. However, auto_increment does not work in a distributed environment because a single database server is not large enough and generating unique IDs across multiple databases with minimal delay is challenging. Here are a few examples of unique IDs: 在本章中,您将被要求在分布式系统中设计一个唯一的 ID 生成器。 你首先想到的可能是在传统数据库中使用具有 auto_increment 属性的主键。但是,auto_increment在分布式环境中不起作用,因为单个数据库服务器不够大,并且跨多个数据库服务器生成唯一 ID 延迟最小的数据库具有挑战性。 以下是唯一 ID 的几个示例:
正常情况下,Redis集群中数据都是均匀分配到每个节点,请求也会均匀的分布到每个分片上,但在一些特殊场景中,比如外部爬虫、攻击、热点商品等,最典型的就是明星在微博上宣布离婚,吃瓜群众纷纷涌入路演,导致微博评论功能崩溃,这种短时间内某些key访问量过于大,对于这种相同的key会请求到同一台数据分片上,导致该分片负责较高成为瓶颈问题,导致雪崩等一些问题。