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
スケーラビリティのためのSansanアプリケーション基盤
Search
Junya Wada
July 28, 2016
Technology
680
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
スケーラビリティのためのSansanアプリケーション基盤
Sansan×gloops インフラ合同勉強会
http://connpass.com/event/33442/
Junya Wada
July 28, 2016
Other Decks in Technology
See All in Technology
[re:Invent2026事前勉強会(有志開催)]続きは、ラスベガスの廊下で / continue-in-the-vegas-hallway
sh_fk2
0
460
AIエージェント統制はAPIから——押さえるべき5つの要素
nagix
0
110
Vue で書く 空間コンピューティング、TresJS と WebXR を使ったXR デバイスのフロントエンド開発
hiranuma
0
140
デザインレビューは自動化できるのか?─ Flutter × Figma で UI 品質保証を考える
techiro
2
700
今から始めるAWS環境の暗号移行 - ポスト量子時代に備える
sato4mi
0
140
攻撃 3 時間 vs 復旧 10 時間。アクセスキー流出の非対称性を体感するために CTF を作った話
kazzpapa3
1
130
Oracle Database Security 詳細解説
oracle4engineer
PRO
1
190
外国人エンジニアがVueプロトタイプで仕様を合わせている話 / Vue Fes Japan 2026 LT
eluwing
0
340
Maestro MCPとClaude Code Skillsによる自律的なE2Eテスト支援
asmz
0
390
AIエージェント時代、Kaggleにどう取り組むか
takanao
2
450
新米を「売り越さない」、Aurora DSQLで作る在庫ゼロ死守の限定ドロップEC
yama3133
0
130
渡米前の準備を制す!re:Invent 2026徹底準備術 / The Ultimate Preparation Guide for re:Invent 2026
yuj1osm
1
470
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
460
Joys of Absence: A Defence of Solitary Play
codingconduct
1
570
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
1
650
The Language of Interfaces
destraynor
162
27k
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
450
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
490
Building Better People: How to give real-time feedback that sticks.
wjessup
371
20k
HDC tutorial
michielstock
2
990
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
Transcript
スケーラビリティのための Sansanアプリケーション基盤 2016年7月28日 #Sansan_gloops
Copyright © 2014 Sansan, Inc. All rights reserved. > 自己紹介
1 • 和田潤也 • 某SIerで8年弱 ⇒ SansanにJOIN • C#、JavaScript 辺り • 主にUI基盤とかを開発していた • 情弱 GitHub: chocolamint
Copyright © 2014 Sansan, Inc. All rights reserved. > え?「インフラ勉強会」…?
2 • インフラの話とはちょっと違います。。。 • アプリケーション基盤の話をします • インフラ要素とも多少絡められたらいいな…
Copyright © 2014 Sansan, Inc. All rights reserved. > スケーラビリティのための仕組み
3 • DBの垂直・水平分散 • 垂直分散 • 役割によってDBを分割 • 水平分散 • ShardingKey によってDBを分割 • ユーザーごとに使うDBを分散するイメージ • メッセージ基盤 • Pub-Sub 型の分散処理基盤 • キューイングサービスを利用
Copyright © 2014 Sansan, Inc. All rights reserved. > DBの分散
4
Copyright © 2014 Sansan, Inc. All rights reserved. > 水平・垂直分散
5 Query Shard Mapping Common Database Use Main data Databases Shard1 Shard3 Shard2 Shard4 News Databases
Copyright © 2014 Sansan, Inc. All rights reserved. > Sansan.Data
6 using (new ShardingScope(shardingKey)) { // ここでの接続は指定されたシャードにいく ... }
Copyright © 2014 Sansan, Inc. All rights reserved. > Sansan.Data
7 Webにおいては ActionFilterAttribute を継承した ShardingFilterAttribute を使って ShardingScope の生成・破棄(Dispose)をしている using (var cn = await ConnectionHelper.OpenDataAsync()) { // 勝手に現在のユーザーが繋ぐべきシャードに繋がる return await cn.Connection.QueryAsync<string>(sql); }
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤
8
Copyright © 2014 Sansan, Inc. All rights reserved. > ちょっと前までのツラみ
9 • 統一的な非同期処理基盤がない • Webアプリのボタンクリックで数分かえって来ない • 同時実行できない • 古い自作基盤が並列処理で死ぬ :yami: • リトライで成功するのにアラート • リレー式の処理の滞留具合がわからない • メンテナンス時の停止と開始がツラい
Copyright © 2014 Sansan, Inc. All rights reserved. > 非同期処理基盤がない
10 • Webアプリで数分かかるボタンクリック • 非同期処理するには個別にバッチ開発が必要 Button Click Insert Record with status = 0 Polling with Task Scheduler FooBar.exe FooBarJob Batch Server Web Server
Copyright © 2014 Sansan, Inc. All rights reserved. > 同時実行できない
11 status = 0 を取得 ↓ 何か処理 ↓ status = 1 に更新 複数台(プロセス)で 対象データを取り合うと死ぬ ↓ 複雑な排他制御が必要(しんどい) ↓ スケールしない Batch Server 1 Batch Server 2
Copyright © 2014 Sansan, Inc. All rights reserved. > リトライで成功するのにアラート
12 タスクマネージャーによる プロセスの定期起動 1分後 アクセス失敗 成功 アラート発砲
Copyright © 2014 Sansan, Inc. All rights reserved. > 処理の滞留がわかりづらい
13 スループット? 対象データの流入
Copyright © 2014 Sansan, Inc. All rights reserved. > 停止と開始の嵐
14 バッチA バッチB バッチC バッチD
Copyright © 2014 Sansan, Inc. All rights reserved. 15 殺伐としたバッチ界にメッセージ基盤が!!
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤
16 Message Queue Web Server Batch Server Enqueue Dequeue Message Server Execute message concurrency SaaS の キューサービスを利用 Message
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤のいいところ
17 • スケールできる • 1プロセス内でマルチスレッドによる並列処理 • キューの種類ごとに並列数を調整可能 • ノードを増やせばさらにスケール可能 • 自動リトライ • 複数回の exponential な自動リトライ • リトライに成功しない場合は dead letter 行き • 自動でアラートメール発砲 • 各処理は冪等であるべき
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤のいいところ
18 • 負荷が安定する • セマフォで並列数制御 • メッセージ毎に異なるキューにルーティング • キューの滞留を監視可能 • グラフでモニタリングも出来る • SaaS でアラームを定義できるので滞留を監視できる
Copyright © 2014 Sansan, Inc. All rights reserved. > メッセージ基盤で出来ること
19 • 1つのメッセージに複数の Subscriber を定義可能 • システムイベントに対する複数処理を割り当て • ex) 新しい名刺が登録されたら… • ◦◦処理を実行 • △△処理を実行 • 全て完了したら××処理を実行 • 安全に停止できる • Windows サービスとして実装 • OnStop でキャンセル要求 • 優先度の高いものから処理できる • キューの種類ごとに優先度別のキューを用意できる
Copyright © 2014 Sansan, Inc. All rights reserved. 20 Mail
Queue (High) Mail Queue (Normal) Mail Queue (Low) News Queue (High) News Queue (Normal) News Queue (Low) 4 parallel 8 parallel
Copyright © 2014 Sansan, Inc. All rights reserved. > コードのイメージ
21 MessageQueue queue; while (true) { var message = queue.ReceiveMessage(); if (message != null) Task.Run(() => DispatchMessage(message)); } var msg = new SendMailMessage("title", "body"); await msg.SendAsync(priority: MessagePriority.Background); 標準で用意されているメッセージ • SendMailMessage • SendAllMailMessage • EventMessage
Copyright © 2014 Sansan, Inc. All rights reserved. > Next...
22 • 実際に基盤に乗っかった処理はまだ一部 • 随時効果の高いところから乗せ換え中 • 現状はメッセージ基盤/バッチのログがテキスト • ツラい • fluentd で Elasticsearch に送り込み Kibana で見れる ように • 絶賛対応中