Chapter 10 System Design inspection point

System test center


Test sites focus

System test center

  • What is the system design?

  • System design need to know what knowledge?

  • How to design and implement a back-end system design services?


What is the system design? (System Design)

Definition of system design is a system architecture, modules, interfaces, and processes the data to meet the specific needs

  • eg: Design a short URL service, service reviews, Feed flow system, grab a red envelope system

  • A short URL service provides a service for all other uses: eg

Many micro-architecture service system is in accordance with the business split, the need for separate design a system service

  • The difficulty of system design

    Senior engineer in the only way

  • Need to have experience in related fields, algorithms, there is a certain architecture design capability
  • Art are familiar with back-end component, eg: message queues, buffers, databases, frame
  • With writing, comprehensive ability flowcharting, architecture design, coding realization

Elements of the system design

Design three elements

  • Usage scenarios and limitations

  • Data Storage Design

  • Algorithm module design

What scenarios and conditions of use?

This system is used where?

  • eg: short URLs station system provides services to generate short URLs

    Restrictions: the estimated number of users? At least be able to support the number of users (service)?

    Concurrent estimate qps: Peak qps is how much? The average qps How much? (Requests per second and how much?)

Design data storage system

Selection Database

  • Demand design data table, which fields need, what type? Scale data growth

  • Database selection: the need for persistence? Use relational or NoSQL?

  • How to optimize? How to design an index? Can I use the cache?

Design algorithm related modules

System = + storage service

  • Interfaces need? How to interface design

  • What algorithm? Or the model?

  • The contrast between the pros and cons of different implementations, how to choose?

How to extend, fault-tolerant?

  • Users more, high qps how to deal with?

  • More than enough to keep data storage how to deal with?

  • How to deal with failure? Single point of failure, multi-point failure, avalanche problem

How to design and implement a short URL system?

What is the short URL system? What features (interfaces) contain?

Short URL storage design system? Which fields need to be stored?

How to design algorithm to generate a short URL?


What is the short URL system?

TinyUrl Service

To turn a long URL into a short URL service

eg: https://bitly.com/

After the conversion URL suffixes no more than seven (character or numeric)

Usage scenarios and limitations

  • Usage scenarios: Provides short URL services to each company's other business services

  • Function: a long URLs into short URLs and storing means, reducing the short long URL url

  • Requirements: a short URL suffix is ​​not more than seven (uppercase and lowercase letters and numbers)

    Estimated peak insert request of magnitude: several hundred, queries magnitude: Thousands

Data Storage Design

The need to design data is stored

  • Using Mysql to meet

  • What are the required fields?

  • How to design an index based on the query?

Mysql Data Sheet

id token (index) url (original site) created_at
1

Algorithm design?

Short URL generation algorithm some? Compare the advantages and disadvantages?

two API: long2short_url, short2long_url

Increment id -?> Counters -> Use redis

​ request->redis incr index->encode(index)->save mysql

#递增序列算法
def mybin(num): #10进制->2进制
    if num == 0:
        return 0
    res = []
    while num:
        num, rem = divmod(num, 2)   # 2 -> 62
        res.append(str(rem))
    return ''.join(reversed(res))

print(mybin(10))

CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

def encode(num):
    if num == 0:
        return CHARS[0]
    res = []
    while num:
        num, rem = divmod(num, len(CHARS)) #62
        res.append(CHARS[rem])
    return ''.join(reversed(res))

print(encode(1))
print(encode(61))

Answer Key

Abide by the three elements to answer

  • Design includes data tables, api design, algorithm

  • Illustrated, there are data tables, interface definition, a flowchart


System Design Questions

How to design a spike system

Difficulties: How to deal with high concurrent user requests

  • What is a spike system?

  • How to design a spike system based on three elements mentioned?

  • Spike system which involves the back-end components

Guess you like

Origin www.cnblogs.com/xuzhaoping/p/11619255.html