Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Smash the Monolith: Refactoring Rails Apps with...
Search
Coraline Ada Ehmke
July 21, 2013
Technology
8
1.2k
Smash the Monolith: Refactoring Rails Apps with Services and APIs
Coraline Ada Ehmke
July 21, 2013
Tweet
Share
More Decks by Coraline Ada Ehmke
See All by Coraline Ada Ehmke
Scaling the Artisan
bantik
0
140
Your First Legacy Codebase
bantik
1
400
Alchemy and the Art of Software Development
bantik
0
290
Artisans and Apprentices
bantik
1
440
Lightweight BI with Ruby, Rails, and MongoDB
bantik
6
2.6k
Better Living Through Open Source
bantik
2
150
Lightweight Business Intelligence in Ruby
bantik
3
1.2k
Beautiful APIs with Faceted
bantik
3
350
Other Decks in Technology
See All in Technology
生成AIのガバナンスの全体像と現実解
fnifni
1
190
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
310
プロダクト開発を加速させるためのQA文化の築き方 / How to build QA culture to accelerate product development
mii3king
1
260
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1.1k
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
マルチプロダクト開発の現場でAWS Security Hubを1年以上運用して得た教訓
muziyoshiz
2
2.3k
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
410
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
2
270
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
170
Featured
See All Featured
A Modern Web Designer's Workflow
chriscoyier
693
190k
Mobile First: as difficult as doing things right
swwweet
222
9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.6k
Automating Front-end Workflow
addyosmani
1366
200k
Making the Leap to Tech Lead
cromwellryan
133
9k
The Language of Interfaces
destraynor
154
24k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
127
18k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Transcript
Smash the Monolith Refactoring Rails Applications
The ‘A’ Word
The definition, composition, and interactions of parts of a system.
Software architecture is...
A compromise between viability and perfection. Software architecture is...
Tempered by the need to deliver a solution. Software architecture
is...
Some science. Lots of aesthetics. Software architecture is...
Software architecture is...
vs. An age-old conflict... Big Up-Front Design Cowboy Coding
Then: Big Up-Front Design
Advantages Long-term product roadmaps Rich design artifacts Guided evolution Predictability
Disadvantages Slow implementation Resistance to change New feature friction No
room for mistakes
Now: Ad-Hoc Architecture
Guiding Principles Convention over configuration Discrete MVC layers Good separation
of concerns RESTful and resourceful
The Best Intentions Test-driven development + pair programming + pull
requests + code reviews = emergent design
The Best Intentions
Non-CRUD controller methods. The Road to Hell
Logic leaking into controllers and views. The Road to Hell
Complex object graphs. The Road to Hell
/lib/ becomes a junk drawer. The Road to Hell
Undocumented gem dependencies. The Road to Hell
Bloated user model. The Road to Hell
Signs of a Degraded Design Rigidity
Signs of a Degraded Design Fragility
Signs of a Degraded Design Immobility
Signs of a Degraded Design Feature friction
Change Gets Harder Over Time Relatively Easy Delegate If Possible
Take a Sick Day KILL IT WITH FIRE Difficulty of Change Time
How did we get here?
How did we get here? Dozens of hands on the
code.
How did we get here? Classes naturally attract new methods.
How did we get here? Increasingly slow test suite.
How did we get here? Entropy.
How did we get here? One line of code at
a time.
“Most software eventually degrades to the point where someone will
declare the design to be unsound.” Uncle Bob Martin
Values-Driven Development
Things We Value Fresh ideas combined with best practices.
Things We Value Solid design principles applied in novel ways.
A Values-Based Approach Culture of innovation + best practices +
solid design principles = better architecture?
Hexagonal Design
Theoretical Backing Layered architectures break down in practice.
Domain Objects HTTP Command Line Testing Messaging Persistence Monitoring Sinatra
Cron Test Unit Beanstalkd Postgres Honey Badger Rails Rake RSpec Rabbit MongoDB New Relic
Design Considerations Design for all of your users, not just
the obvious ones.
Design Considerations Give every class its own distinct API.
Design Considerations Write your application in pure Ruby.
Theoretical Backing Achieve framework independence.
Using APIs & Messages
Write programs that do one thing and do it well.
Write programs to work together. Write programs to handle text streams, because that is a universal interface. Doug McIlroy, Bell Labs CSRC HTTP
Design Considerations Implement an ecosystem of small applications.
Design Considerations Divide models between the applications.
Design Considerations Persistence is a service.
Design Considerations Bind applications together using APIs and messaging.
Design Considerations Determine a caching strategy.
Design Considerations Pick a messaging solution.
Rethinking Architecture
Roots Rock.
A Sudden Revelation What if we think of an application...
...as just another object?
Object-Oriented Architecture
Theoretical Backing Apply OO design principles to the architecture itself.
Classes communicating via messages Applications communicating via APIs & queues
! Theoretical Backing
Applying OO Principles An application is a group of components
that perform tasks on the same data.
Applying OO Principles An application should do one well-defined thing.
Applying OO Principles APIs allow us to easily extend our
interfaces.
Applying OO Principles It doesn’t matter what application sends, receives
or processes our messages.
Applying OO Principles APIs and presenters allow us to easily
create client-specific interfaces.
Legacy Applications
What is a legacy app? Age is not measured in
months or years or versions.
What is a legacy app? Legacy code is not broken.
What is a legacy app? Don’t git blame.
What is a legacy app? A storehouse of information about
a problem space.
Refactoring Tactics Dismantle god classes.
Refactoring Tactics Extract behaviors into modules.
Refactoring Tactics Extract models and business logic into engines.
Refactoring Tactics Migrate engines into discrete applications.
Refactoring Tactics Implement observers using a messaging service.
Refactoring Tactics Provide persistence through asynchronous services.
Refactoring Tactics Direct calls between applications rely on a good
set of APIs.
Refactoring Tactics Use your API as a guide to refactoring
your models.
Synchronous Calls via APIs Credentials Auth Token Auth Service Client
App
Asynchronous Calls via Message Queues Prefs Update Client App Attr
Change Persistence Service
Refactoring Tactics Find functional edges and refactor them into services.
Refactoring Tactics Make liberal use of the presenter pattern.
A declarative framework useful for building APIs. faceted.rb
On the Other Side of Refactoring
A Small App Ecosystem Consumer App Internal App 1 Internal
App 2 Persistence API Messaging API Reporting API Dashboard App
Reap the Benefits Reduced cost of change.
Reap the Benefits Support for unexpected and novel use cases.
Reap the Benefits Reduction of ceremony around releases.
Reap the Benefits Low-impact downtime.
Reap the Benefits Short ramp-up time for new developers.
Reap the Benefits Increased performance of test suites.
Reap the Benefits A/B testing on applications and infrastructure.
Reap the Benefits Greater flexibility.
Reap the Benefits Democratization of application architecture.
Go smash your monolith.
smashthemonolith.com Corey Ehmke @bantik