周韋伶
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # System Design ## 議題討論 ### 何謂 System Design?系統設計的流程與步驟為何? **System design** 是指設計一個系統的**架構、部件、介面**的流程,目的是要達成系統使用者的需求。 系統設計生命週期(development life cycle) - 一、需求分析與開發計畫:透過實際考察、資料分析等方式,找到可能的需求以及限制。 - 二、定義需求:詳細定義所有需求,並得到所有相關人員同意(開發者、消費者、股東等等),通常會制定 Software Requirement Specification(SRS)。 - 定義每秒需求、儲存容量、需要哪些功能 - 三、架構設計:這個階段需要考慮需求以及系統的複雜度(performance、availability、scalibility 等等),決定外來不同的部件間如何整合 - 前端、後端、DB - 演算法、table怎麼設計、API規格 - 四、系統開發:透過已撰寫好的文件進行需求的實作 - 五、系統測試與整合:單元測試以及整合各個部件,確保系統能夠正確提供服務,架構的性能也在此時被測試 - 六、部屬和系統維護:系統部屬後,後續的更新以及維護 架構設計: - 辨識複雜度:思考並定義此系統在延展性、可用性以及效能上的需求,了解架構需要著重於哪個部分 - 設計備選方案 - 評估和選擇方案 - 詳細方案設計(實作) ### 什麼是 High Performance、High Availability、Scalability? - **高可用性(High Availability)**:取決於**正常運行時間(uptime)** 長度以及**功能反應時間**,一些機構像是醫院、金融等負擔不起過長的等待時間就需要高可用性的系統。 - **可靠性(Reliability)**:當系統可以正確的提供所有的功能和服務(features & services),那麼系統便是 **Reliable**。可靠的系統需要一定程度的[**故障容許度(fault tolerance)**](https://zh.m.wikipedia.org/zh-hant/%E6%95%85%E9%9A%9C%E5%AE%B9%E8%A8%B1%E5%BA%A6),讓系統不會因為某些功能的故障導致系統故障。 - **高效能(High Performance)**:系統在特定工作量下的效能,是 scalability 以及 availability 的綜合指標。 - Response Time - Throughput - Resource utilization - Workload - **延展性(Scalability)**:指系統的流量負載量(work load),透過調整系統負載流量的方式去適應高流量的情境,流量可能是: - 系統指令(request) - 資料庫指令 - Cache hit/miss - 當前活躍使用者 ### 如何提升系統的 Performance? https://ithelp.ithome.com.tw/articles/10081534 ### 何謂資料庫讀寫分離? * 使用原因:因為多數場景都是讀多寫少,為了減緩讀檔壓力 * 主要架構:主從式設計 * 寫入:先寫入主DB,再由主DB寫入從DB * 讀檔:基本由從DB負責 https://codingnote.cc/zh-tw/p/276299/ ### Cache 如何提升系統效能?該放在系統哪個位置? 減少資料庫操作;前端 提升複雜計算速度;後端 ### 如何提升系統的 High Availability? ![](https://i.imgur.com/hQjhkNQ.png) https://www.filecloud.com/blog/an-introduction-to-high-availability-architecture/ ### 何謂 CAP 理論?該如何選擇? * Constitency - 一致性 * Availability - 可用性 * Partition Tolerance - 分區容錯性 ##### CAP Theorem * CAP不可能同時滿足三點,於是分為三種情況 * CA - 基本上是單一主機運行 * CP - 確保所有主機資料一致,否則回傳錯誤 * AP - 基本不報錯,但不保證資料是最新 https://ithelp.ithome.com.tw/articles/10216500 ### Database 的 Replication 有哪些模式? * **Master Slave Replication 主從式** * https://www.manageengine.com/device-control/data-replication.html ### 如何提升系統的 Scalability? - 程序執行方式 - 非同步程序:讓回應速度慢的程序已非同步的方式執行,確保其他功能的的流量可以先被解決 - 程序排程(queue) - 硬體加速 - 分散式系統(w/ load balancer) - Cache 複雜計算時所需要的資料 - 資料庫操作限制 - Cache 機制 - Idexing 搜尋 ### 何謂微服務與分層架構? * **分層架構**中的一個重點在於**當某一層進行更改時,通常不應該影響到非相關依賴層** ,而分幾層可以按場景靈活應用(n-tier architecture),例如:很多公司會根據組織結構(前端工程師、後端工程師、DBA)做分層。 * **微服務**是一種軟體開發的方法,將**應用拆解為最小單位的獨立元件**。以臉書為例,可以拆解成動態牆、影片、個人檔案、照片等,而這些功能的程式碼再由不同團隊更新、部署、維運。 #### 分層架構 * 大部分的分層架構會分成這四層: ![分層架構圖](https://i.imgur.com/uvMVPfJ.png) 1. **表示層 (Presentation Layer)**:處理所有用戶界面和瀏覽器通信邏輯。 3. **業務層 (Business Layer)**:處理軟體本身特定的業務邏輯。 4. **持久層 (Persistence Layer)**:注於資料的儲取活動。 5. **資料訪問層 (Data Access Layer)**:外部資料來源 (通常獨立於應用程式)。 * 為什麼要分層?分層的好處? * **易於理解與開發**:程式邏輯很線性,資料流不是從上到下就是從下往上 * **關注點分離(Separation of concerns, SoC)**:該層只處理與該層相關的邏輯,可以有效分割功能,讓開發、測試與維護變得更簡單。 * **可測試性**:分層獨立更容易模擬單元測試。 * 參考資料 * [軟體架構:分層架構模式 (Layered Architecture)](https://medium.com/%E7%A8%8B%E5%BC%8F%E6%84%9B%E5%A5%BD%E8%80%85/%E8%BB%9F%E9%AB%94%E6%9E%B6%E6%A7%8B-%E5%88%86%E5%B1%A4%E6%9E%B6%E6%A7%8B%E6%A8%A1%E5%BC%8F-layered-architecture-a959da09d1c6) * [從分層架構到微服務架構(二)之分層架構](https://www.readfog.com/a/1632288208805007360) #### 微服務 ![微服務](https://i.imgur.com/hea5t3G.png) * 基本特點 * 每個服務運行在自己的process中 * 使用輕量級協議(RESTful APIf、gRPC)做通訊(Lightweight Mechanism) * 透過自動化部屬來完成獨立部屬 * 按照業務能力(Business Capability)來區分規劃各服務範圍 * 各服務可以使用不同的語言來開發, 也可以使用不同的資料儲存媒介 * 參考資料 * [菜鳥漫步雲端 #3: 什麼是微服務(Microservices)](https://medium.com/@yijyun10100926/%E8%8F%9C%E9%B3%A5%E6%BC%AB%E6%AD%A5%E9%9B%B2%E7%AB%AF-3-%E4%BB%80%E9%BA%BC%E6%98%AF%E5%BE%AE%E6%9C%8D%E5%8B%99-microservices-51d8b873d252) * [微服務瞎談(2) 服務與架構的演化](https://ithelp.ithome.com.tw/articles/10234821) ## 案例研究 ### Design Rate Limiter ### Design ID Generator ## 實作 ### 1. Stylish DB放到RDS ### 2. AWS Auto Scaling + Artillery + Rate Limiter ### 3. 實作 ID Generator

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully