Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to Work with Legacy Ruby on Rails Applications in Treasure Data

How to Work with Legacy Ruby on Rails Applications in Treasure Data

PLAZMA TD Tech Talk 2018 at Shibuya

Shimpei Makimoto

October 16, 2018
Tweet

More Decks by Shimpei Makimoto

Other Decks in Technology

Transcript

  1. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    How to Work with Legacy Ruby on Rails Applications in Treasure Data Shimpei Makimoto, API Team Arm Treasure Data 16 October 2018 PLAZMA TD Tech Talk 2018 at Shibuya
  2. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    こんにちは • Shimpei Makimoto • API Team, Arm Treasure Data since November 2017 • TD では特に認証認可に関することをやっている • https://github.com/makimoto • https://twitter.com/makimoto
  3. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Goals of this presentation • Treasure Data の内部においてウェブ API アプリケーションやそれを開発・運用す る API チームが果している役割について知ってもらう • 最近の API チームのチャレンジについて紹介する
  4. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Goals of this presentation • Treasure Data の内部においてウェブ API アプリケーションやそれを開発・運用す る API チームが果している役割について知ってもらう • 最近の API チームのチャレンジについて紹介する • あわよくば、採用サイトからわれわれのチームに応募してもらう
  5. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    PR https://www.treasuredata.com/company/careers/ もうすぐ Senior Web Backend API Engineer というタイトルのポジションが開くと思うの で、興味がある人は声かえてください。 (このトークまでに出せたらよかったけど間に合わなかった……)
  6. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Contents • What is “API” and “API Team” in TD • Recent updates about our API service(s) • Working in progress (最近やっていること)
  7. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    What is “API” in TD? • “Treasure Data についてのウェブ API を提供するサービス” • 具体的には、“td-api” レポジトリ (private) に含まれる Ruby on Rails プロジェクト のこと • (主にサービスの観点で) “api3” の名でも呼ばれる • 開発・運用しているのは API Team
  8. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    API Team • td-api の開発・運用に責任を負う • この発表時点で 6 人のチーム (5人が東京近辺在住、1人が Colombia 在住) ◦ Ruby コミッタ1人 ◦ Rails コミッタ2人 • @kamipo さんが ActiveRecord の最新機能をバックポートしたりして便利 • ウェブアプリケーション開発や運用のバックグラウンドを持つ人が多い
  9. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    td-api - our API service • Ruby on Rails で作られたウェブアプリケーション • 7歳 • 行数の観点では極めて大規模というわけではない
  10. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    API’s responsibilities I thought before • アカウント情報やジョブやユーザデータベースの管理 • これらを実現する JSON を話す RESTful API エンドポイントの提供
  11. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Actual API’s responsibilities • アカウント情報やジョブやユーザデータベースの管理 • これらを実現する JSON を話す RESTful API エンドポイントの提供 • 複数の用途の API (公開用、コンソール用、内部コンポーネント用) の維持 • 前世代のコンソールのためのフロントエンド実装の維持 • 認証 • 認可 • 管理画面 • 外部サービス連携のためのロジック • データインポートのためのロジック • etc. etc.
  12. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Actual API’s responsibilities • システム全体の結合のための機能のかなりの部分が含まれる • 創業間もなくから作られたコンポーネント (7歳) なのでレガシーな部分も多い
  13. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    7-year-old Rails app • `rails new`ed by Kaz Ohta on 1 Jul 2011 • Started with ◦ JRuby 1.6.2+ ◦ Rails 3.0.9
  14. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    What are challenges for “API” developers in TD • 開発開始からかなり時間が経った Rails アプリケーションの開発・運用 • 社内外複数のコンポーネントと協調的にやりとりする必要性
  15. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    One year ago (when I joined to TD) • td-api ◦ Ruby 2.3.3 ◦ Rails 4.2.10 ◦ Hosted on EC2/IDCF Cloud directly
  16. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Current • td-api ◦ Ruby 2.3.3 → Ruby 2.5.1 ◦ Rails 4.2.10 → Rails 5.0.7 (※発表時 5.0.2 とありましたがこれは誤りで、実際は 5.0.7 でした) ◦ Hosted on EC2/IDCF Cloud directly → Hosted on Docker containers • connection-api ◦ TD-hosted な Embulk の設定などの管理が別サービスに分離
  17. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Other kaizens in the last few months • Rails が生成する X-Request-Id ヘッダの値を Rails アプリ間で持ち回るようにし、 各種ログに記録されるようになり、エラー追跡などに使えるようになった • 伝統的に大量に使用されている RAILS_ENV の数が減った • 内部コンポーネントが公開 API と内部 API の両方を叩いていたのを内部 API だけ 使うようになった
  18. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Working in progress (最近やっていること)
  19. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Separating Access Control • td-api ではアクセス制御に CanCanCan という gem を使っている • td-api が見ているリソース以外のアクセス制御も取り扱いたい • CanCanCan は Rails に強く依存しているので我々のユースケースから離れてきて いる • →新しいサービスを作ってアクセス制御の役割を担わせたい
  20. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    New service or not • 当初の計画: 新しい独立したアプリケーションを建てる • 現在の計画: 最初に td-api 内のコンポーネントとしてサービスを実装する
  21. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    New service or not • 当初の計画: 新しい独立したアプリケーションを建てる • 現在の計画: 最初に td-api 内のコンポーネントとしてサービスを実装する • 複数サービス間のやりとりは設計に不具合があった際のリカバーが面倒 ◦ サービス分割の分断面を見誤ると後で直すのが大変 ◦ そもそも動いた段階でプロダクトの要求が変わる可能性がある • 新規サービスだとゆるい制約だけで分割可能なコンポーネントを既存サービス内に作 れる ◦ 逆に既存サービスの分割だと歯をくいしばる以外なさそう
  22. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Basic idea on separating services graduatelly “main service” (具体的には td-api) 内に “sub service” のコンポーネントを作る sub service のデータベースは main service のものとは分ける main service sub service main service DB sub service DB
  23. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Basic idea on separating services graduatelly “main service” が “sub service” を使う際 は必ず所定のインターフェースを使う インターフェースは create_permission み たいなメソッドを提供しているが、 CQRS と イベントソージングなどを採用することもでき る main service sub service interface
  24. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Separating services graduatelly “interface” と対応するウェブ API を用意し て “main service” からの使用をウェブ API 経由にする HTTP リクエストのオーバーヘッドなどが許 容できるか評価するのもこの段階 main service sub service interface Web API HTTP
  25. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Separating services graduatelly これまでの段階で十分な要件を果たしてい ることが確認できたら、満を持してサービス を分割する サービスを建てたら基本的にコンシューマ 側 (“main service”) のエンドポイントを切り 替えるだけで実現できる main service sub service Web API HTTP sub service interface Web API interface
  26. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Separating services graduatelly • 段階的にサービスを分割していくというアイディア • 今進めているところなので応援してください • もっと良いアイディアがあれば教えてください
  27. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Contents • What is “API” and “API Team” in TD • Recent updates about our API service(s) • Working in progress (最近やっていること)
  28. Copyright 1995-2018 Arm Limited (or its affiliates). All rights reserved.

    Wrap up • Treasure Data では Rails アプリケーションとどうつきあっているか紹介した • 今のところ銀の弾丸は見つかってないので、着実に進めるしかなさそう • TODO: 採用ページのリンクを貼る