---
# System prepended metadata

title: code tpl
tags: [mock interview, 面試]

---

# code tpl

{%hackmd theme-dark %}


E4 
    do things right

E5 trade-offs (

    SQL / NOSQL, 

    core puzzle, 

    push pull, 

    REST/GraphQL/GRPC, 

    sync or async ( message queue→ also decoupe

    bandwidth → use websockey instead

E6 go deep ( offline support, multi-language support, battrey optimal


E7 
System Design: Log exchange event for on-premise analysis or ML


purpose:
1. us eu trading log -> us or eu server -> TW 

usecase:
1. write log to local server
2. send back to main server (TW) 

metric:
every day log -> 100 milion

RPS:
    1157.40740741 request / second
    - LB server number -> scale out
    - scale up -> CPU / MEM-> base on statistics

storage:
    1 log 1KB -> 100 million -> 100GB / day
    - database / plan for storage

bandwidth : upload -> 100GB / 86400 -> 1MB / s
    - ISP network


database
- log
    - write perfer
    - time series 
- cassandra DB



user produce log -> [LB] -> (log service) -> [cassandra DB]
                                                |
                                                relica to main server -> TW [cassandra]
                                                                              |
                                                                            ML analyisis

usecase:
1. write log to local server
    - user log -> hit LB
    - LB -> dispatch log service
    - log service wirte to cassandra

2. send back to main server (TW) 
    - regular replica to main server

1. cassandra DB by location
 - single point failure 
 - N (log service) -> dispatch by LB
 - cassandra -> availibilty
 - write freqency -> ? cassandra LSM(mem) ->  full? -> disk ss stable

 - producer -> 1 ms. write latency 10 ms
  - write mem cache -> hard digest traffic
  - 16 hr active
  - cassandra 10 ms X witre op 
  -> data -> LSM(mem) -> full -> sstable , 10 ms

pararell -> memory 









  1 
2   3  
  4
# 1 -> 4
# 1. shortest path for ans
# 2. sakeholder ask information

# 1. build ralstionship 0:[1], 1:[0], 2:[3] ...
# 2. shortest path -> BFS 
# iter1 src 2
# it2   -> 3 -> 2 in seen
# it3   -> 4  -> dst -> [2, 3, 4]

def sol(weight, edges, src, dst):
    # weight [1, 2, 3, 4, 5]
    # edges: [[0, 1], [2, 3], [3, 4]]



```python=


```

###### tags: `mock interview` `面試`