20240219-Chat-Server-Ood

Question

  • 請解釋你會怎麼設計一個chat server,請說明你會怎麼設計Backend Component的細節、Class及Method,可能需要解決最困難的問題是什麼

Solution

  • 這問題很大,一開始要scope problem,一開始建議從廣下手,但focus可以再inerview完成的部分
  • focus 使用者管理(新增、建立對話、更新狀態)
  • 先不管網路、資料怎麼傳送給client等問題
  • 要加入聯絡人,要兩方都是才是,支援群組聊天、一對一私人對話,不考慮語、音通話或檔案傳輸

What specific action does it need to support?

  • 與interviewer討論,for example:
    • singing online and offline
    • 加入request(sending, accepting and rejeccting)
    • 更新狀態
    • 建立private 及群組訊息
    • 在private及群組對話加入訊息

What can we learn about these requirements?

  • 我們需要有使用者、新增request狀態、線上狀態、訊息

What are the core components of the system?

  • 使用database永久儲存資料,SQL很好,如果要scalability,可以使用BigTable之類
  • client-server溝通可以使用XML,因為人跟機器可讀,但他不是最好壓縮過的格式
  • 資料可能被切分在不同機器,為了避免single point of failure,資料會複製好幾份在不同機器

What are the key objects and methods

  • key objects, includes users, conversations, status message
    • UserManager
      • userById: map(int=>User)
      • userByAccountName: map(string=>User)
      • onlineUsers: map(int=>User)
      • addUser()
      • approveAddRequest()
      • rejectAddRequest()
      • iserSignedOn()
      • iserSignedOff()

What problems would be the hardest to solve(or the most interesting)?

  • 可能會interviewer討論以下問題
  • Q1: How do we know If someone is online–I mean, really know?
    • 有可能使用者忘記登出,定時去ping client看是否還在
  • Q2: How do we deal with conflicting information
    • 有些存databse,有些存電腦的memory,如果有些out of sync怎麼辦?哪個才正確?
  • Q3: How do we make our server scale?
    • 如何設計可以擴展的系統,真實世界資料可能要拆分在不同機器,怎麼處理不同步資料

Ref

20240216-Levelsfyi-Crawler

Background

GET https://api.levels.fyi/v3/salary/search?countryIds[]=197&offset=10&limit=50&sortBy=offer_date&sortOrder=DESC&jobFamilySlug=software-engineer
  • response
{
    "payload": "EofXi7jF2t63a..."
}

solution

  • Go to levels.fyi> Inspect>Network>JS tab>commonUtils.js>CryptoJS.AES.decrypt
  • I wrote a python script :
from Crypto.Cipher import AES
from Crypto.Hash import MD5
from base64 import b64encode, b64decode
import zlib
class ResponseUtil:
    def __init__(self):
        self.key = "levelstothemoon!!"
        self.n = 16

    def parse(self, t):
        if "payload" not in t:
            return t
        r = t["payload"]
        a = MD5.new(self.key.encode()).digest()
        a_base64 = b64encode(a)[: self.n]
        cipher = AES.new(a_base64, AES.MODE_ECB)

        decrypted_data = cipher.decrypt(b64decode(r))
        
        decompressed_data = zlib.decompress(decrxypted_data)

        return json.loads(decompressed_data.decode())

# Example usage:
response_util = ResponseUtil()
parsed_data = response_util.parse(ans)
print(parsed_data)
{
    "total": 1000,
    "hidden": 2,
    "rows": [
        {
            "uuid": "079fb0cf-d9ff-4b58-bb08-70f3a8447521",
            "title": "Software Engineer",
            "jobFamily": "Software Engineer",
            "level": "E7",
            "focusTag": "General",
            "yearsOfExperience": 5,
            "yearsAtCompany": 2,
            "yearsAtLevel": 2,
            "offerDate": "2024-01-27T02:02:19.682Z",
            "location": "Hsin-chu, TP, Taiwan",
            "workArrangement": "office",
            "compPerspective": "employee",
            "cityId": 17410,
            "dmaId": 10064,
            "countryId": 236,
            "exchangeRate": 31.2881,
            "baseSalary": 42188.5583,
            "baseSalaryCurrency": "TWD",
            "totalCompensation": 67757.3815,
            "avgAnnualStockGrantValue": null,
            "stockGrantCurrency": null,
            "avgAnnualBonusValue": 25568.8232,
            "bonusCurrency": "TWD",
            "salesComp": null,
            "negotiatedAmount": null,
            "gender": null,
            "ethnicity": null,
            "education": null,
            "otherDetails": null,
            "companyInfo": {
                "registered": true,
                "icon": "https://logo.clearbit.com/mediatek.com",
                "name": "MediaTek",
                "slug": "mediatek"
            },
            "vestingSchedule": null,
            "tags": null,
            "stockType": null
        },
        ...

contract

If you have any questions or needs, please contract me at alan.tseng.cs@gmail.com

20240217-Call-Center-Ood

Question

有一個有三種level員工的call center,respondent, manager, director。當電話進來時,要assign給空閒的respondent,如果他不能回答,必須轉介給manager,也不行就往上給director,設計一個給這問題的class及資料結構,實作一個dispathchCall()指派電話給低一個可用的員工

20240217-Jigsaw-Ood

Question

打造一個拼圖遊戲,設計資料結構以及解釋如何破解這個拼圖的演算法。你可以假設有一個fitsWith(),他可以檢查兩個拼圖是否可以拼在一起。

0%