Software engineering notes

Backend

安全性

設計 RESTful API 注意地方

避免使用 cookie, 因違反無狀態協議, 如果只用來記錄 client 資料不維護狀態, 那麼還是可以使用

session 則完全違反 REST 的無狀態性

解決方式是 client 登入後產生 token, 再從 url 帶 token 過來

驗證身份方法1. 永遠使用 ssl, 就不用每次讓用戶對每次請求簽名

驗證身份方法2. server 將 token 加/解密對應到 session ID, application server 再用 session ID 取得用戶資料判斷權限

增加網站效能

server

後端

前端

mysql

關於 App

Storage

Notification Title

Distributed System (Sub/Pub)

Log 系統

  1. CloudWatch Log agent 丟到 cloudwatch 或是直接用 Kinesis agent 丟到 Kinesis Streams
    • 上面任一方法 -> Kinesis Firehose (log) -> s3
    • 上面任一方法 -> Kinesis Firehose (log) -> Kinesis Analytics (SQL query) -> Firehose (result) -> s3
  2. ELK stack : ElasticSearch(搜尋引擎) + Kibana(顯示圖表/結果) + Logstash (收集 log, 也可用 filebeat/FluentD)
  3. Telegraf / Collectd + InfluxDB + Grafana 易安裝
  4. Fluentd + Prometheus + Grafana

2,3,4 都要自已架, 成本也高

ref:

DST 時間 (日光節約時間)

某些國家會調整當地時間以符合日光節約時間,當程式在處理不同國家時間時就要注意了,將時間轉成 dst 存下來, 可以使用別人寫好的第三方來轉,下次取時再將 utc 轉成 dst 撈出來。

Functional programming

Functional programming is a programming paradigm that emphasizes the use of functions to transform and manipulate data, rather than modifying the state of objects. In functional programming, functions are treated as first-class citizens, which means they can be passed as arguments to other functions, returned as values from other functions, and composed together to build more complex functionality. This approach is in contrast to imperative programming, where the state of objects is changed through commands and statements. The goal of functional programming is to write code that is easy to reason about, test, and maintain by eliminating side effects and promoting immutability and purity of functions. Common functional programming languages include Haskell, Lisp, and Erlang.

Dynamic programming

Dynamic programming is a method for solving problems by breaking them down into smaller sub-problems and solving each sub-problem only once to obtain solutions for larger problems. The solutions to the sub-problems are stored in a table, so that they can be reused instead of recomputing them, thus saving time and increasing efficiency. Dynamic programming is often used to solve optimization problems, such as finding the shortest path between two points or the longest common subsequence of two strings, among others.

如何避免 response header X-Content-Type-Options: nosniff

如果 MIME 類型與 URL 的 MIME 類型不匹配,則不允許讀取該檔案

我還不是很了解這個實際判斷的方式是什麼, 但我加上 cookie 後, 就可以下載 google drive 的檔案了

CORS

chrome 會先發一個 method: OPTIONS 的 request 測試是否通, 但不會幫你加上 body 及 header

Proxy vs Reverse Proxy

Proxy 後面的 server 有直接對外

Reverse Proxy 後面 server 沒有直接對外

Concurrency vs Parallelism

Testing

Unit Testing

Integration Testing

Functional Testing

Acceptance Testing

Regression Testing

To make sure your new feature won’t break the existing functionality of the application. You have to run all of the tests including itself’s test.

Test Doubles

ref: