Skip to content

πŸ₯‡ first come, first served rest api server which processes many request effectively under multi-thread environment.

Notifications You must be signed in to change notification settings

funchcode/play-fcfs-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

μ„ μ°©μˆœ μ„œλΉ„μŠ€ - API Server

πŸ₯‡ first come, first served.
REDIS, SQS, NoSQL을 μ‚¬μš©ν•΄λ³΄κΈ° μœ„ν•΄ λ³Έ ν”„λ‘œμ νŠΈλ₯Ό κΈ°νšν–ˆμŠ΅λ‹ˆλ‹€.
λΆ€μ‘±ν•œ 점이 λ§Žμ€λ° 객관적인 지적, μ‘°μ–Έ ν•΄μ£Όμ‹œλ©΄ κ°μ‚¬ν•˜κ² μŠ΅λ‹ˆλ‹€.πŸ™‚

μˆ˜λŸ‰μ΄ μ œν•œλœ μ–΄λ– ν•œ λŒ€μƒμ΄ 있고 μ‚¬μš©μžλ“€μ€ λŒ€μƒμ˜ μ‚¬μš© κΆŒν•œμ„ μ–»κΈ° μœ„ν•΄ νšλ“ μš”μ²­μ„ ν•œλ‹€.
λ§Žμ€ μ‚¬μš©μžλ“€μ΄ μ œν•œλœ λŒ€μƒ μ‚¬μš© κΆŒν•œμ„ κ°–κΈ° μœ„ν•΄ λ°œμƒν•˜λŠ” λ‹€μˆ˜μ˜ μš”μ²­μ„ κ²¬λ”œ 수 μžˆλŠ” μ„œλ²„λ₯Ό ꡬ좕해보렀고 ν•œλ‹€.

기술적 λͺ©ν‘œ

Java

Redis

API μ„œλ²„ λ‹¨μ—μ„œ νŠΈλž˜ν”½μ„ λΉ λ₯΄κ³  효율적으둜 μ²˜λ¦¬ν•˜κΈ° μœ„ν•΄ Redisλ₯Ό μ‚¬μš©ν•˜κΈ°λ‘œ κ²°μ •ν–ˆλ‹€.
λ©”λͺ¨λ¦¬ 기반둜 λΉ λ₯΄κ²Œ 데이터λ₯Ό 읽올 수 μžˆλŠ” Key-Value Store DB인 Redisλ₯Ό κ²½ν—˜ν•΄λ³Έλ‹€.

SQS

API μ„œλ²„μ˜ λΆ€ν•˜λ₯Ό 쀄이고 μš”μ²­λœ μˆœμ„œλ₯Ό 보μž₯λ°›κΈ° μœ„ν•΄ AWS SQSλ₯Ό μ‚¬μš©ν•˜κΈ°λ‘œ κ²°μ •ν–ˆλ‹€.

DynamoDB

Serverless, Fully managed ν™˜κ²½μΈ NoSQL DBλ₯Ό ν•™μŠ΅ν•΄λ³΄κΈ° μœ„ν•΄ AWS DynamoDBλ₯Ό μ‚¬μš©ν•˜κΈ°λ‘œ κ²°μ •ν–ˆλ‹€.


Structure

structure.png


μ• ν”Œλ¦¬μΌ€μ΄μ…˜ μž‘λ™ 방식

λŒ€μƒ(SUBJECT)

ν•œμ • μˆ˜λŸ‰μ˜ Ticket을 μ„€μ •ν•˜κΈ° μœ„ν•΄ λŒ€μƒ(SUBJECT)λ₯Ό 등둝해야 ν•œλ‹€.
μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ AWS DynamoDB에 Writeν•˜λŠ” μž‘μ—…μ€ SUBJECTλ₯Ό λ“±λ‘ν•˜λŠ” μΌ€μ΄μŠ€λ§Œ ν—ˆμš©ν•œλ‹€.

ν‹°μΌ“(TICKET)

이번 ν”„λ‘œμ νŠΈμ˜ λͺ©ν‘œλŠ” μˆœκ°„μ μΈ νŠΈλž˜ν”½μ„ λŒ€μ‘ν•  수 μžˆλŠ” μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ κ΅¬μΆ•ν•˜λŠ” 것이닀.
ν‹°μΌ“(TICKET) νšλ“ μš”μ²­μ—μ„œ μˆœκ°„μ μΈ νŠΈλž˜ν”½μ„ λ°œμƒν•œλ‹€λŠ” 것을 κ°€μ •ν•˜κ³  μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ„ κ΅¬μΆ•ν–ˆλ‹€.
λŒ€λŸ‰μ˜ μš”μ²­μ€ 1차둜 Redisμ—μ„œ 필터링을 ν•œλ‹€. Redisμ—μ„œ μ œν•œλœ μˆ˜λŸ‰μ„ μ΄ˆκ³Όν•˜λŠ” μš”μ²­μΈ 경우λ₯Ό λ°”λ‘œ νŒŒμ•…ν•˜κ³  Responseλ₯Ό ν•œλ‹€.
정상적인 μš”μ²­μ€ Redis β†’ SQS β†’ Worker νλ¦„μœΌλ‘œ μš”μ²­μ΄ 흐λ₯Έλ‹€.
Ticket λ°μ΄ν„°λŠ” AWS DynamoDBμ—μ„œ Read μž‘μ—…λ§Œ ν•œλ‹€. Write μž‘μ—…μ€ Consumer Workerμ—μ„œ μ§„ν–‰ν•œλ‹€.


도메인

μ˜ˆμ•½ν•  λŒ€μƒμ„ μ˜λ―Έν•˜λŠ” Subject
μ˜ˆμ•½ν•˜λŠ” 주체λ₯Ό μ˜λ―Έν•˜λŠ” Client
λŒ€μƒμ— 주체가 μ˜ˆμ•½ν–ˆμŒμ„ μ˜λ―Έν•˜λŠ” Ticket

λŒ€μƒ(Subject)

μ΅œλŒ€ν•œ μ‹¬ν”Œν•œ μ •λ³΄λ§Œ κ°–λŠ”λ‹€.
μƒμ„Έν•œ μ •λ³΄λŠ” ν˜ΈμΆœν•˜λŠ” μ™ΈλΆ€ μ‹œμŠ€ν…œμ—μ„œ κ΄€λ¦¬ν•˜λ„λ‘ μœ λ„ν•œλ‹€.
μ‹œμŠ€ν…œμ— λ“±λ‘λœ 주제 μ •λ³΄λŠ” DB둜 κ΄€λ¦¬ν•œλ‹€.

속성(μ˜μ–΄) 속성(ν•œκΈ€) μ„€λͺ…
ID 식별 κ°’ μ–΄λ–€ 주제λ₯Ό νŠΉμ •ν•˜λŠ” 식별 κ°’
OPEN_DATE μ˜€ν”ˆλ‚ μ§œ μ˜ˆμ•½ μ˜€ν”ˆ λ‚ μ§œ
DEADLINE_DATE λ§ˆκ°λ‚ μ§œ μ˜ˆμ•½ 마감 λ‚ μ§œ
LIMITED_QUANTITY_OF ν•œμ •μˆ˜λŸ‰ ν•œμ • μˆ˜λŸ‰ 정보
STATUS 데이터 μƒνƒœ [진행전, 진행쀑, μ·¨μ†Œ, μ’…λ£Œ]
❔ SYSTEM_ID ❔ λ“±λ‘ν•œ μ‹œμŠ€ν…œ 정보 ❔ * κ³ λ €ν•˜μ§€ μ•ŠμŒ *

주체(Client)

μ˜ˆμ•½ν•˜λŠ” 주체에 λŒ€ν•œ μ •λ³΄λŠ” 보톡 μ‚¬μš©μž 정보일 것이닀.
μ‚¬μš©μž 정보 μ—­μ‹œ μ™ΈλΆ€ μ‹œμŠ€ν…œμ—μ„œ κ΄€λ¦¬ν•˜λ„λ‘ μœ λ„ν•œλ‹€. λ”°λΌμ„œ λ³Έ μ‹œμŠ€ν…œμ—μ„œλŠ” 주체에 λŒ€ν•œ μ •λ³΄λŠ” DB둜 κ΄€λ¦¬ν•˜μ§€ μ•ŠλŠ”λ‹€.

μž…μž₯ꢌ(Ticket)

주체(Client)κ°€ νŠΉμ • λŒ€μƒ(Subject)에 λŒ€ν•΄ μ†Œμœ κΆŒμ„ κ°–κ²Œ λ˜λŠ” 경우 μž…μž₯κΆŒμ„ κ°–λŠ”λ‹€λΌλŠ” 의미둜 Ticket으둜 λͺ…λͺ…ν–ˆλ‹€.
μž…μž₯κΆŒμ— λŒ€ν•œ μ •λ³΄λŠ” μ‹œμŠ€ν…œμ—μ„œ DB에 μ €μž₯ κ΄€λ¦¬ν•œλ‹€.

속성(μ˜μ–΄) 속성(ν•œκΈ€) μ„€λͺ…
CLIENT_ID μ†Œμœ κΆŒμž μž…μž₯κΆŒμ„ μ†Œμœ ν•œ λŒ€μƒ
SUBJECT_ID 주제 μ–΄λ””(주제) μž…μž₯ꢌ
CREATED_AT μ†Œμœ ν•œ λ‚ μ§œ μ†Œμœ κΆŒμ„ 얻은 λ‚ μ§œ

πŸ“Œ 주체(Client)λŠ” νŠΉμ • 주제(Subject)에 λŒ€ν•œ μž…μž₯ꢌ(Ticket)을 ν•˜λ‚˜λ§Œ μ†Œμœ ν•  수 μžˆλ‹€.
πŸ“Œ λ“±λ‘ν•œ 주제(Subject) μ •λ³΄λŠ” μˆ˜μ •ν•  수 μ—†λ‹€. ν•„μš”ν•˜λ‹€λ©΄ μƒˆλ‘œ λ“±λ‘ν•΄μ„œ μ‚¬μš©ν•˜λ„λ‘ ν•œλ‹€.


DB λͺ¨λΈλ§

Primary Key Attributes
PK(Partition Key) SK(Sort Key) openDate deadlineDate limitedQuantityOf status createdAt updatedAt
subject#{subjectId1} info 2023-12-31T12:24 2024-01-31T12:24 100 ONGOING 2023-11-18T22:30:45.292739 2023-11-18T22:30:45.292739
Primary Key Attributes
PK(Partition Key) SK(Sort Key) createdAt
subject#{subjectId1}#ticket client#{clientId1} 2023-12-31T12:24

πŸ“Ž μ‹œλ‚˜λ¦¬μ˜€λ₯Ό μ •λ¦¬ν•œλ‹€.
πŸ“Ž REST API λ¬Έμ„œ


β˜• 도움을 μ£Όμ‹  λΆ„

🀝 김지황 λ‹˜
Redis&Kafkaλ₯Ό ν™œμš©ν•œ μ„ μ°©μˆœ 쿠폰 이벀트 개발기 (feat. λ„€κ³ μ™•)
μ„ μ°©μˆœ μ‹œμŠ€ν…œ 섀계λ₯Ό κ³ λ―Όν•˜λ‹€ 김지황 λ‹˜μ΄ μ“°μ‹  μœ„μ˜ 글을 보게 λ˜μ—ˆκ³  κΆκΈˆν•œ 뢀뢄이 메일을 λ³΄λƒˆλŠ”λ° μž‘λ…„μ— μ“΄ κΈ€μ΄μ—ˆμŒμ—λ„ λΆˆκ΅¬ν•˜κ³  μ§ˆλ¬Έμ— λŒ€ν•΄ μƒμ„Έν•˜κ²Œ ν”Όλ“œλ°±μ„ ν•΄μ£Όμ…”μ„œ ν”„λ‘œμ νŠΈλ₯Ό μ§„ν–‰ν•˜λŠ” 데에 λ§Žμ€ 도움이 λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

About

πŸ₯‡ first come, first served rest api server which processes many request effectively under multi-thread environment.

Topics

Resources

Stars

Watchers

Forks

Languages