首页 > 其他分享 >System Design Interview

System Design Interview

时间:2024-04-14 21:45:44浏览次数:30  
标签:index use business Business System API Design Interview geohash

1 Proximity Service

1) requirements

  Functional Requirements Non-Functional Requirements
1

Return all businesses based on user's location (latitute and longitute pair) and radius (5km)

Low latency.

  • Users see nearby business quickly
2

Business owners can use Restful API to deal with a business.

  • not to be refelcted in real-time

Data privacy

  • comply with GDPR & CCPA
  • location info is private
3 Custerms can view business detail

High availability and scalibility requirements.

  • Proximity Service can handle the spike in traffic during peak hours

 

2) Basic Culculatiion

QPS

Seconds in a day = 24 * 60 * 60 = 86400, round it up for 10**5. 

Users: 100 million

Searches: 5 times.

QPS: 100m * 5 / 10**5 = 5000

5000
Users 100 million  
Business 200 million  

 

3) High Level Design

User API design

Users search for business.

  • Restful API
  • Pagination

Parameters.

  • latitude
  • longitude
  • radius

{

"radius": 10,

"business": [business Object]

}

GET / search / nearby  
Business API design

Restful API.

  • GET
  • POST
  • UPDATE
  • DELETE
   
Data model

Read / Write Ration

Read:

  • Read-heavy system

Write:

  • Write is infrequent operation.

Schema

  • Geo index table (geohash and businessid)
  • business table (detail about business)

MySql. (PostgreSQL)

 
Algorithms to find near by business

1) Geohash

problems:

  • not enough business. 1) return the results directly. 2) remove the last index.

 

2) Quatree

 

   

 

4) design diagram

Load Balancer

receive requests (latitute, longitute, radius) from users 

Location-based service

Responsibility

  • calculate geohash from a user and neibor geohash
  • call redis for nearby businessids and business_objects
  • calculate distance extra
  • rank result to return
  • pagination

 

characters:

  • read-heavy service
  • QPS is high during the peak
  • the service is stateless so it is easy to scale horizontally

 

it is a multi location services. 

  • users are physically close to local services
  • can set up a region DNS to follow the local laws or requirements.
Business Service
  • write infrequently
Database Cluster
  • primary-second setup
  • data is saved in primary database then replicated to replicas
  • some discrepency between replicas and primary databse is not an issue

Scale:

1) Business Table

  • Good for sharding

2) Geo index Table

 

  • not sharding (sharding is not a good choice)
  • use read replicas
Redis Cluster

Caching is not necessary. Because read geo index from database is fast enough.

we can use cache to handle the spike during peak hours.  We use caching to enhance the performance.

1) key: geohash, value: [business_list]

storage for value: 200 m * 32 bytes * 3 precisions = 17gb

storage for key: negligible.

 

we deploy this cache globally to ensuer hive availability

2) key: businessid, value: business_object

 

2 nearyby friends

标签:index,use,business,Business,System,API,Design,Interview,geohash
From: https://www.cnblogs.com/ylxn/p/18134741

相关文章

  • Vue3、AntDesignModal、useModal.js封装组件
    useModal.jsimport{nextTick,ref}from'vue'import{isFunction}from"lodash-es";exportfunctionuseModal(){ constvisible=ref(false) constloading=ref(false) constshowModal=()=>{ visible.value=true } con......
  • PowerDesigner 业务流程/数据建模软件和元数据管理解决方案
    拓展阅读数据库设计工具-08-概览数据库设计工具-08-powerdesigner数据库设计工具-09-mysqlworkbench数据库设计工具-10-dbdesign数据库设计工具-11-dbeaver数据库设计工具-12-pgmodeler数据库设计工具-13-erdplus数据库设计工具-14-NavicatDataModeler数据库设计工具-......
  • SystemVerilog -- 2.1 Data Types ~ New Data types
    SystemVeriloglogicandbit在上一篇文章中,概述了主要数据类型。在本会话中,我们将研究4-state和2-state变量以及两种名为logic和bit的新数据类型。4-statedatatypes除了0和1之外,还可以具有未知(X)和高阻态(Z)值的类型称为4态类型。请注意,只能在过程快中驱动,例如,数据类......
  • SystemVerilog -- 2.0 Data Types ~ Introduction
    SystemVerilogDataTypesSystemVerilog是Verilog的扩展,也用作HDL。Verilog具有和数据类型来描述硬件行为。由于硬件验证可能变的更加复杂和苛刻,Verilog中的数据类型不足以开发高效的测试平台和测试用例。因此,SystemVerilog通过添加更多类似C的数据类型和扩展Verilog,以......
  • SystemVerilog -- 1.1 Introduction ~ tb
    我们需要一个称为testbench的环境对设计运行任何类型的仿真。Whatisthepurposeofatestbench?Testbench允许我们通过仿真来验证设计的功能。它是一个容器,其中放置设计并使用不同的输入激励进行驱动。生成不同类型的输入刺激使用生成的激励驱动设计输入允许设计处理输......
  • c# System.Guid
    转帖自:http://blog.163.com/very_apple/blog/static/27759236201182744327193/概念GUID:即GloballyUniqueIdentifier(全球唯一标识符)也称作UUID(UniversallyUniqueIDentifier)。GUID是一个通过特定算法产生的二进制长度为128位的数字标识符,用于指示产品的唯一性。GUID主......
  • 【论文随笔】会话推荐系统综述(A Survey on Conversational Recommender Systems)
    前言今天读的论文为一篇于2021年5月发表在《ACM计算机调查》(ACMComputingSurveys)的论文,文章提供了对话式推荐系统(CRS)的全面综述,探讨了CRS的定义、概念架构、交互方式、知识元素、计算任务以及评估方法。文章还讨论了CRS在不同应用环境中的实现,如智能家居助手和聊天机器人,并指......
  • 读论文-电子商务产品推荐的序列推荐系统综述与分类(A Survey and Taxonomy of Sequent
    前言今天读的这篇文章是于2023年发表在"SNComputerScience"上的一篇论文,这篇文章主要对序列推荐系统进行了全面的调查和分类,特别是在电子商务领域的应用。文章首先定义了用户和产品集合,以及用户与产品的交互序列。然后,它解释了序列推荐系统的目标,即生成一个个性化的Top-K排名的......
  • 【论文随笔】基于会话的推荐系统构建方法调查(Survey On Methods For Building Sessio
    前言今天读的论文为一篇于2023年发表在国际开放信息技术杂志(InternationalJournalofOpenInformationTechnologies)的论文,文章是关于构建基于会话的推荐系统(Session-basedRecommenderSystems,SBRS)的方法的综述。文章首先介绍了推荐系统在处理大量信息领域(如在线商店、电......
  • 读论文-基于会话的推荐系统综述(A survey on session-based recommender systems)
    前言今天读的论文是一篇于2021年发表于"ACMComputingSurveys(CSUR)"的论文,文章写到,推荐系统在信息过载时代和数字化经济中非常重要。基于会话的推荐系统(SBRSs)是新的推荐系统范式,不同于其他模型化长期静态用户偏好的推荐系统,SBRSs专注于捕捉短期动态用户偏好。尽管SBRSs已被深......