--- tags: recruitment --- 如果每題都是 1 ~ 5 分,你覺得你自己應該得到幾分?(自己的分數自己給) ## 1. 軟體工程與程式碼風格/組織能力 ### 1-1. 如何組織一個小型後端專案?你會如何劃分模組或檔案? 下面有一個任務管理系統,該系統允許建立使用者、更新、查看和刪除任務。系統需具備基本的認證功能,以確保只有已登入的用戶才能管理自己的任務。 請試想如果要做這樣的一個系統,你會需要新增哪些資料夾和檔案(不用實際寫 code)。然後請告訴我們,這些檔案各自應該負責什麼?為什麼應該擺在那個資料夾? #### **需求描述** 1. **用戶註冊和登入**: - 用戶可以註冊新帳戶,提供用戶名、電子郵件和密碼。 - 用戶可以登入,成功登入後會獲得一個 JWT(JSON Web Token)作為後續 API 請求的認證標記。 2. **任務管理**: - 每個用戶可以創建、查看、更新和刪除他們自己的任務。 - 每個任務包括以下資料: 3. **權限控制**: - 只有已登入的用戶可以操作他們自己的任務,無法查看或修改其他用戶的任務。 #### **基本功能 API** 1. **用戶註冊**:`POST /users/register` - 請求資料:`{ username, email, password }` - 返回資料:註冊成功後的用戶信息 2. **用戶登入**:`POST /users/login` - 請求資料:`{ email, password }` - 返回資料:JWT token 3. **創建任務**:`POST /tasks` - 請求資料:`{ title, description, dueDate, status }` - 返回資料:創建的任務資料 4. **查看任務**:`GET /tasks` - 請求資料:JWT token(作為 Authorization header) - 返回資料:當前用戶的所有任務列表 5. **更新任務**:`PUT /tasks/:id` - 請求資料:`{ title, description, dueDate, status }` (根據需要更新的欄位) - 返回資料:更新後的任務資料 6. **刪除任務**:`DELETE /tasks/:id` - 請求資料:JWT token(作為 Authorization header) - 返回資料:刪除確認 ### 1-2. 當你發現一段程式碼可以優化時,你會如何處理?如何向團隊提出建議? 這邊有一段程式碼,請試著整理它,整理成你覺得最乾淨的樣子。 你認為這樣的「整理」是有意義嗎?如果你覺得有意義,但這樣努力和產出可能永遠都不會被看見,你會抱持什麼樣的心態? ```typescript function calculateTotal(cart) { let total = 0 for (let i = 0; i < cart.length; i++) { const item = cart[i] if (item.available) { if (item.discount > 0) { total += item.price - item.discount } else { total += item.price } if (item.coupon) { if (item.coupon.type === 'percentage') { total -= (total * item.coupon.value / 100) } else if (item.coupon.type === 'fixed') { total -= item.coupon.value } } } } return total } const cart = [ { price: 100, available: true, discount: 10, coupon: { type: 'percentage', value: 20 } }, { price: 50, available: false, discount: 0 }, { price: 200, available: true, discount: 0, coupon: { type: 'fixed', value: 30 } } ] console.log(calculateTotal(cart)) ``` ### 1-3. 命名 - 假設資料庫有一個 collection,負責儲存各種辨識時的參數,譬如當人臉特徵向量多少達到 cosine similarity 多少時我們可以把兩個向量視為來自同一張人臉,攝影機每隔多久捕捉一次人臉,作人形偵測時感興趣的畫面範圍(由多個點所圍成的多邊形範圍)等等,你覺得這個 Collection 要命名叫什麼比較好? - 假設有另外一個 Collection,儲存著「如何將好幾個辨識設定,按加/減法作進一步的整合」的參數(譬如說 A 入口進入的人次 + B 入口進入的人次 - C 出口離開的人次),你覺得這個 Collection 要叫什麼比較好? ## 2. 語言特性熟悉度(針對 TypeScript) ### 2-1. as unknwon as 這邊的 `as unknown as ObjectId` 有更好的做法嗎? ```typescript import { type Db, type Collection, type ObjectId } from "mongodb" import { Collections } from "@/constants" import { type AlertPolicy } from "@/modules/Monitoring/dtos/AlertPolicy" export class AlertPolicyRepository { protected collection: Collection constructor({ db }: { db: Db }) { this.collection = db.collection(Collections.AlertPolicies) } async set(_id: string, record: Partial<AlertPolicy>) { const now = Date.now() const $setOnInsert = { createdAt: now } const $set = { ...record, updatedAt: now, } await this.collection.updateOne({ _id: _id as unknown as ObjectId }, { $set, $setOnInsert }, { upsert: true }) } async delete(...$in: string[]) { await this.collection.deleteMany({ _id: { $in: $in as unknown as ObjectId[] } }) } async get(_id: string) { const alertPolicy = await this.collection.findOne<AlertPolicy>({ _id: _id as unknown as ObjectId }) if (!alertPolicy) return undefined return alertPolicy } } ``` ### 2-2. infer & never ```typescript type ExtractArrayType<T> = T extends (infer U)[] ? U : never ``` 請回答以下問題: 1. 按你的看法,這邊的 ExtractArrayType 類型是用來做什麼的? 2. 寫出 ExtractArrayType<string[]> 的結果。 3. 寫出 ExtractArrayType<number> 的結果。 4. 為什麼這裡應該要用 never 而不是 unknwon? ### 2-3. path alias 如何設定讓我們可以使用 typescript path alias 功能作引入,而不是每次都透過相對路徑。 ## 3. 基礎設施架設/演算法及資料結構的使用經驗 ### 3-1. 有用過哪些服務? - mysql - postgressql - mongo - redis - minio - etcd - rabbitmq - kafka - kql - qdrant - firebase realtime database - firestore - firebase auth - firebase FCM - auth0 - cloud function - lambda - ecs - ec2 - eks - s3 - cloud logging - cloud run - gae - gas (google app script) - gce ### 3-2. 向量索引 請設計一個資料結構及演算法,我們要在 1 秒內從 108 萬個向量中找到最鄰近且通過 score threshold 的向量(假設向量都是 512 維 32-bit 浮點數)。 如果沒辦法馬上想出合適的資料結構或演算法,請評估 3 個 opensource 且你覺得可用的服務,然後說說看你會選哪一個以及為什麼。 ### 3-3. CI/CD 你有使用過哪些 CI/CD 工具(如 Jenkins、GitLab CI 等)? 你如何設計自動化部署流程? ### 3-4. 把 docker image 編譯成 FROM scratch 有什麼好處? 使用 nexe 或 pkg 的話如何實現(要運行在 linux amd64 上)。 ### 3-5. 日誌管理 你會選用什麼套件寫系統日誌?考量到有一天日誌可能會寫到 external storage 的話,你會選用什麼工具/服務? ### 3-6. 為什麼我們應該選用外部的 message broker 而不是在程式裡面 sleep + 從超大陣列裡面拉任務出來消化? ### 3-7. 為什麼我們應該選用資料庫而不是檔案系統儲存要搜尋的資料? ### 3-8. 為什麼我們應該選用 dotenv 載入環境變數? ### 3-9. ~~請嘗試說明 SPA、SSR、SSG、ISG 有什麼分別。~~ - ~~SPA、SSR 每次 request 都會拿資料嗎?~~ - ~~SPA 只拿資料(肉)嗎?還是連頁面(骨)都重拿?~~ - ~~比起 SSG,ISG 會在什麼時候情況下重新產生頁面?~~ ![image](https://hackmd.io/_uploads/By9qmDY30.png)