Conditional Statement

TypeScript는 JavaScript와 동일한 조건문 구문을 사용하지만, type checking을 통해 code의 안전성을 높인다.

if-else Statement

기본적인 조건 분기 구문으로, 조건에 따라 다른 code block을 실행한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// 기본 if-else 구문
const age = 25;

if (age >= 18) {
console.log("Adult");
} else {
console.log("Minor");
}

// 여러 조건 확인 (if-else if-else)
const score = 85;

if (score >= 90) {
console.log("Grade: A");
} else if (score >= 80) {
console.log("Grade: B");
} else if (score >= 70) {
console.log("Grade: C");
} else {
console.log("Grade: F");
}

// TypeScript에서의 type narrowing
function process(value: string | number) {
if (typeof value === "string") {
// 이 block 내에서 value는 string type으로 처리됨
return value.toUpperCase();
} else {
// 이 block 내에서 value는 number type으로 처리됨
return value.toFixed(2);
}
}
Read more »

호텔 예약 시스템

  • Airbnb system 설계
  • 항공권 예약 system 설계
  • 영화 ticket 예매 system 설계

1단계: 문제 이해 및 설계 범위 확정

아래 세부 사항은 가상 면접관과의 대화를 통해 문제를 이해하고, 설계 범위를 정의한 내용이다.

  • 비기능 요구사항
    • 높은 수준의 동시성 (concurrency): 성수기, 대규모 event 기간에는 일부 인기 hotel의 특정 객실을 예약하려는 고객이 많이 몰릴 수 있음
    • 적절한 지연 시간: 사용자가 예약할 때 응답 시간이 빠르면 이상적이지만 예약 요청 처리에 몇 초 정도 소모되는 것은 괜찮음
  • 개략적 규모 추정
    • 총 5,000개 hotel, 100만 개의 객실 가정
    • 평균적으로 객실의 70% 사용, 평균 투숙 기간은 3일로 가정
    • TPS (Transactions Per Second)
      • 일일 예약 건수 $=\frac{10^6\times0.7}{3}=233,333\simeq240,000$
      • 초당 예약 건수 $=\frac{240,000}{10^5}\simeq3$
    • QPS (Queries Per Second)
      • Hotel/객실 상세 page: 사용자가 hotel/객실 정보 확인 (조회 발생)
      • 예약 상세 정보 page: 사용자가 날짜, 투숙 인원, 결제 방법 등의 상세 정보를 예약 전 확인 (조회 발생)
      • 객실 예약 page: 사용자가 ‘예약’ button을 눌러 객실 예약 (Transaction 발생)
      • 대략 10%의 사용자가 다음 단계로 진행, 90%의 사용자는 이탈한다 가정
      • $\therefore$ $3\ (TPS) * 10 * 10 = 300\ (QPS)$
Read more »

Introduction

Feature JavaScript (JS) TypeScript (TS)
Type System Dynamic Static + Dynamic
Compilation Interpreted (runtime) Compiled to JS (transpile)
Type Checking No Yes (compile-time)
IDE Support Basic Advanced (IntelliSense, etc.)
Learning Curve Easy Slightly higher
Community Very large Large, growing
Ecosystem Huge Uses JS ecosystem
Error Catching Runtime Compile-time + Runtime
Annotation Not required Optional (but recommended)
OOP Support Prototype-based Class-based (ES6+), Interface
Install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
$ npm install -g typescript
$ npm init -y
Wrote to /path/to/package.json:
...
$ tsc --init
Created a new tsconfig.json with:
target: es2016
module: commonjs
strict: true
esModuleInterop: true
skipLibCheck: true
forceConsistentCasingInFileNames: true
You can learn more at https://aka.ms/tsconfig
Read more »

Introduction

LLM이 발전하면서 distributed training, serving이 점점 더 중요해지고 있다.
분산 환경에서 cluster 간 통신은 필수적이고, 저지연/고처리량 network가 핵심이다.
PyTorch, DeepSpeed, vLLM 등 다양한 framework로 쉽게 구현할 수 있지만 (물론,,, 처음엔 삽질을…), 이러한 기술들의 이해도를 높히기 위해 본 글을 작성한다.

Read more »

광고 클릭 이벤트 집계

Ad click event aggregation system: A system designed to collect, process, and analyze data related to ad click events. It ensures real-time processing and accuracy of data, crucial for digital advertising processes like Real-Time Bidding (RTB), where transactions must be completed within a second.

  • RTB (Real-Time Bidding): Digital 광고의 핵심 process, 실시간 경매 절차를 통해 지면 (inventory) 거래
    • 1초 내에 모든 process가 마무리 돼야 함
  • Ad click event aggregation
    • Online 광고가 얼마나 효율적이었는지 측정하는 데 결정적 역할 $\rightarrow$ 광고주가 얼마나 많은 돈을 지불할지 영향
    • 결과에 따라 광고 campaign 관리자는 광고 예산을 조정하기도 하고, target group이나 keyword를 변경하는 등 광고 전략을 수정하기도 함
    • 핵심 지표: CTR (Click-Through Rate), CVR (Conversion Rate)
Read more »