Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
総会員数1,500万人のレストランWeb予約サービスにおけるRustの活用
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kōhei Yamamoto (山本浩平)
November 30, 2024
Technology
3.6k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
総会員数1,500万人のレストランWeb予約サービスにおけるRustの活用
Rust.Tokyo 2024 一休スポンサーセッションでの発表資料です
Kōhei Yamamoto (山本浩平)
November 30, 2024
More Decks by Kōhei Yamamoto (山本浩平)
See All by Kōhei Yamamoto (山本浩平)
一休.comレストランにおけるRustの活用
kymmt90
3
1.2k
一休.comレストランのRustバックエンド開発の様子
kymmt90
15
12k
レガシーWebアプリケーションの性能とコードの健全性をインクリメンタルに改善する / pepabotech-20211209
kymmt90
1
3.1k
コードレビュー座学 / About code reviews
kymmt90
0
6.9k
ペパボのWebサービス 開発スタイル / Web services development at GMO Pepabo
kymmt90
2
640
GraphQL and Schema-First Development
kymmt90
4
4.2k
EC新サービスにおけるスキーマファースト開発 / Schema First Development in the New EC Service
kymmt90
1
2.5k
rails new --api してからやったこと 〜2017年・夏〜 / EC Tech MTG 3
kymmt90
0
940
カテゴリ階層の拡張を目的とした階層的トピックモデル / A hierarchical topic model for expanding category hierarchies
kymmt90
0
650
Other Decks in Technology
See All in Technology
Reactの設計論
uhyo
24
13k
AIに任せた品質は、誰が見立てるのか - AI時代のテストマネジメント
nakanao
2
1.7k
Minecraft JavaのMODをSwiftで作る
1mash0
0
170
Claude Code本って、 読む必要あるの?
oikon48
2
470
CLIライブラリ開発を支える技術
htnabe
0
120
Slack上でインフラをトラブルシュートする! Agentic Platform Engineeringの第一歩
teru0x1
5
1.7k
俺の仕事は AIに奪われないし、たぶんその BIも要らない
hikaruri
0
500
銀行勘定系システムにおける開発プロセス刷新×AIによる環境モダナイゼーション / Development Process Transformation and AI-Driven Environment Modernization
muit
0
2.2k
DEFCON34-Write-up_HYCu-MYCu
daikiokazaki
0
160
技術的負債から考える、AI時代のエンジニアリング投資 — ビズリーチの技術的負債と向き合った経験から、変更し続けられるソフトウェアを考える/ technical-debt-con2026
visional_engineering_and_design
3
3k
Claude Codeを「使うほど育つ」AI秘書にするノウハウ
minorun365
PRO
30
26k
DEFCON_CHV_CTF_Write-up.pdf
bata_24
0
150
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
580
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
360
Accessibility Awareness
sabderemane
1
210
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.6k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Everyday Curiosity
cassininazir
0
320
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
240
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Prompt Engineering for Job Search
mfonobong
0
450
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Transcript
0 総会員数1,500万人のレストラン Web予約サービスにおけるRustの活用 山本浩平 | 2024-11-30 Rust.Tokyo 2024
1 自己紹介 • 山本浩平 @kymmt90 • 2023年に一休に入社し、一休.comレストランの Rustでの開発に途中から参加
2 本発表で話すこと • 一休.comレストランについて • Rust活用の詳細 ◦ バックエンド ◦ エッジコンピューティング
• 今後のチャレンジ
3 一休.comレストラン | サービス概要 • 上質なレストランの Web予約サービスを提供 • 2006年ローンチの長い 歴史を持つサービス
4 一休.comレストラン | サービス概要 • 一休.com全体の会員規模1,500万人 • バックエンドへのトラフィックは最大1,000req/sほど (夕方〜夜が多い)
5 一休.comレストラン | Rustを利用中 • システムのさまざまな箇所をRustに移行中 ◦ Web UI バックエンドのGraphQL
API ◦ 社内の他システムとの連携用REST API ◦ Fastly Computeでのエッジコンピューティング ◦ [WIP] Solr (全文検索エンジン)のインデクサー
6 本発表で話すこと • 一休.comレストランについて • Rust活用の詳細 ◦ バックエンド ▪ 概要と設計
▪ 技術トピック ◦ エッジコンピューティング • 今後のチャレンジ
7 Rustバックエンド | 概要 GraphQL API REST API frontend app
internal systems SQL Server フレームワークはAxum GraphQL実装にはasync-graphqlを利用 Python, C#などからの移行 Solr Fastly (後述) internal systems backend
8 バックエンド | Rustの選定理由 • 「シンプル、かつすばやく、それでいて堅牢に作れる」 という社内の技術選定方針に基づく ◦ 表現力の高い型システムでドメインモデルをコード化 ◦
高速/省リソース: 運用コストを中長期的に改善 ◦ crateによるモジュール依存関係の制御 ◦ 社内で利用する技術のバランス
9 バックエンド | 設計 • クエリモデル ◦ C向け予約サービスの 特性上、表示用の 非正規化されたデータが
ほしい場面が多いので、 クエリモデルを導入 DB, フレームワーク, 環境の設定 dataloaderのI/Fやユースケースなど エンティティ (クエリモデル) データアクセス層など
10 バックエンド | 設計 [例:データアクセス層] async fn fetch_restaurants<C: Config>( &self,
database: &crate::Database<C>, keys: &[RestaurantId], ) -> Result<HashMap<RestaurantId, Result<Restaurant>>> { let query = format!( // クエリ ); // レコードフェッチ、 DTOからクエリモデルへ let restaurant_models = database .query_as::<dto::Restaurant>(&query, params) .await .context("failed to query restaurants")? .into_iter() .map(|d| (d.id, Restaurant::try_from(d))) .collect(); Ok(restaurant_models) } 具体的なDBや設定は外から注入 上位層→モデルの依存方向になり モデルは外界に依存しない
11 バックエンド | モジュールの設計 • Cargo Workspaceでリポジトリ内をモジュラーに ◦ 各層(実際はもう少し細粒度)をworkspace crateで表現
◦ 各crateのCargo.tomlでcrate間の依存の向きを強制 # ルートディレクトリのCargo.toml [workspace] resolver = "2" members = [ "backend/*", ] [workspace.dependencies] backend-query-model = { path = "./backend/query-model" } # ...
12 バックエンド | モジュールの設計 • workspace.dependenciesで設定した特定のcrateへの 依存をCargo.tomlに明記 # データアクセス層のCargo.toml [package]
name = "backend-data-access" version.workspace = true authors.workspace = true edition.workspace = true publish.workspace = true [dependencies] backend-query-model = { workspace = true }
13 本発表で話すこと • 一休.comレストランについて • Rust活用の詳細 ◦ バックエンド ▪ 設計
▪ 技術トピック ◦ エッジコンピューティング • 今後のチャレンジ
14 バックエンド | utoipaでOpenAPI記述 • 社内用REST APIはutoipaでOpenAPIドキュメントを記述 • Rust内からもドキュメントにアクセスできるので、リクエストボディ のバリデーションにOpenAPI上のJSON
Schemaを使う ◦ Axumのextractorを定義 ◦ ハンドラでリクエストボディを使うときに自動バリデーション
15 バックエンド | utoipaでOpenAPI記述 pub struct ConformantJson<T>(pub T); #[async_trait] impl<S,
T> FromRequest<S, Body> for ConformantJson<T> where // ... { type Rejection = ApiError; // IntoResponseである必要あり async fn from_request(req: Request<Body>, state: &S) -> Result<Self, Self::Rejection> { // utoipa::openapi::OpenApiの参照から特定のレスポンスボディのJSONスキーマを取得できるようにしてある let schema = OPENAPI_DOC .get_request_body_schema(path, &req.method().clone().into()) .expect("..."); match Json::from_request(req, state).await { Ok(Json(body)) => match validate_json_schema_conformance(&schema, &body) { Ok(_) => { let deserialized = serde_json::from_value(body).expect("..."); Ok(ConformantJson(deserialized)) } // 400エラーを返すApiError Err(err) => Err(err), }, Err(rejection) => // ... } } } ConformantJsonという構造体にAxumの FromRequestを実装することで、 JSON Schemaでリクエストボディを バリデーションしてから取り出すextractorを 作る
16 バックエンド | utoipaでOpenAPI記述 #[utoipa::path( post, path = "/internal/coupon-settings", request_body(
content = CouponSetting, content_type = "application/json", ), responses(/* ... */), )] pub async fn create_coupon_setting( State(state): State<AppState>, ConformantJson(new_coupon_setting): ConformantJson<CouponSetting>, ) -> Result<impl IntoResponse, ApiError> { // ... } extractorであるConformantJsonで CouponSettingを取り出すとき、 そのJSONスキーマでバリデーションされ、 エラーなら自動で400 Invalid Requestを返す utoipaのマクロ (utopia::path , utoipa::ToSchema な ど)でPOST /internal/coupon-settings の スキーマを定義する
17 バックエンド | CPUバウンドな処理の扱い • 一休では検索時の席在庫計算処理などがCPUバウンド ◦ Tokioなど非同期ランタイムはawaitで他タスクに切替 ◦ CPUバウンドな処理でブロックしてawaitまでに時間がかかると…
▪ 他タスクに切り替わらずスレッド数上限以上には並行できない ▪ 結果、他のリクエストが詰まったりする • Rayonのスレッドプールに処理を委譲し、それをawaitすることで 問題を解決 (cf. https://ryhl.io/blog/async-what-is-blocking/#the-rayon-crate)
18 バックエンド | CPUバウンドな処理の扱い pub async fn spawn_rayon<F, R>(f: F)
-> R where //... { let (tx, rx) = tokio::sync::oneshot::channel(); rayon::spawn(move || { let _ = tx.send(f()); }); rx.await.expect("...") } // CPUバウンドな処理を実行する let res = spawn_rayon(move || /* 席在庫計算などの処理 */).await?; CPUバウンドな処理はRayonに任せて 結果だけチャンネル経由で受け取る CPUバウンドな処理が動くタスクを awaitできるので非同期ランタイムが タスク切り替えできる
19 本発表で話すこと • 一休.comレストランについて • Rust活用の詳細 ◦ バックエンド ◦ エッジコンピューティング
• 今後のチャレンジ
20 エッジコンピューティング | CDNキャッシュ • 店舗探し体験の改善は顧客価値につながる ◦ 高速にレスポンスするためにCDNからキャッシュ配信 ◦ 一休ではFastlyを利用
• キャッシュロジックを少し工夫したい ◦ パーソナライズされないページでキャッシュ ◦ 会員のランクに応じたコンテンツをキャッシュ ◦ etc.
21 エッジコンピューティング | Fastly Compute • Fastly Computeを導入 ◦ エッジ上でWASMを実行。ロジックをRustで記述可能
◦ 一休.comレストランではVCLでの設定から移行中 ▪ コードが読みやすい、テストが書きやすい
22 エッジコンピューティング | Fastly Compute #[fastly::main] fn main(mut req: Request)
-> Result<Response, Error> { // ... let resp = handle(req.clone_with_body())?; // ... Ok(resp) } fn handle(mut req: Request) -> Result<Response, Error> { let backend = select_backend(&req); let resp = match &backend { Backend::RustBackend(cache_type) => { if !req.get_method().is_safe() { return Ok(req.with_pass(true).send(backend.name())?); } match cache_type { CacheType::Cache(options) => { // キャッシュ制御ロジック }, CacheType::CacheWithCacheGroup(options) => { // 会員ランクごとのキャッシュ制御ロジック }, // ... #[fastly::main]を付与したmain でリクエストをハンドリングする RustのコードとしてCDN上での キャッシュ制御やリクエスト振り分け を実装できる
23 本発表で話すこと • 一休.comレストランについて • Rust活用の詳細 ◦ バックエンド ◦ エッジコンピューティング
• 今後のチャレンジ
24 今後のチャレンジ | 予約コアロジックの移行 • VBScriptで書かれWindows Server上で動く、予約作成、 変更、キャンセルなどを担うシステム (サービス開始当初から存在) •
VBScriptは2027年ごろWindowsからデフォルト無効化 https://techcommunity.microsoft.com/t5/windows-it-pro-blog/vbscript-deprecation-timelines-and-next-steps/ba-p/4148301
25 今後のチャレンジ | 予約コアロジックの移行 • 新規予約、変更、キャンセル、割引やポイント付与を含む 既存のVBScriptからRustへの移行 • Rustのコードとして、どうデータモデルを表現するかから 取り組むことが求められる
26 エンジニアを募集しています https://www.ikyu.co.jp/recruit/engineer