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
1.2k
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Smash the Monolith: Refactoring Rails Apps with Services and APIs
Coraline Ada Ehmke
July 21, 2013
More Decks by Coraline Ada Ehmke
See All by Coraline Ada Ehmke
Scaling the Artisan
bantik
0
180
Your First Legacy Codebase
bantik
1
460
Alchemy and the Art of Software Development
bantik
0
380
Artisans and Apprentices
bantik
1
560
Lightweight BI with Ruby, Rails, and MongoDB
bantik
6
2.8k
Better Living Through Open Source
bantik
2
190
Lightweight Business Intelligence in Ruby
bantik
3
1.2k
Beautiful APIs with Faceted
bantik
3
380
Other Decks in Technology
See All in Technology
product engineering with qa
nealle
0
150
環境凍結という Toil を倒す -セルフサービス型 Ephemeral テスト環境の 設計と実践
shirouz
1
1.8k
スタートアップにおけるアジャイルの実践について #shibuyagile
murabayashi
3
2.1k
Keeping applications secure by evolving OAuth 2.0 and OpenID Connect
ahus1
PRO
1
150
AI Agent SaaS を支える自社仮想化基盤への挑戦と実運用 / ai-agent-saas-virtualization
flatt_security
2
3.3k
cccccc
moznion
0
1.8k
プライバシー保護の理論と実践
lycorptech_jp
PRO
1
250
Foxgloveについて 実際にExtensionを開発して公開するまでの話 / About Foxglove: The Story of Developing and Releasing an Extension
ry0_ka
0
190
ローカルLLMとLINE Botの組み合わせ その3 / LINE DC Generative AI Meetup #8
you
PRO
0
130
Amazon EVS で VCF 9.0 / 9.1 のサポート開始まとめ
mtoyoda
0
280
LiDAR SLAMの実装とセンサ融合 ~Lie群からContinuous-Time LIOまで~
naokiakai
1
1k
CSに"SLO"は要らない、経営層に"99.9%"は伝わらない - SREを全社に"翻訳"する3原則
cscengineer
PRO
1
3.8k
Featured
See All Featured
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
220
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
Leo the Paperboy
mayatellez
8
1.9k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
How GitHub (no longer) Works
holman
316
150k
WCS-LA-2024
lcolladotor
0
680
Technical Leadership for Architectural Decision Making
baasie
3
430
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
360
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
170
Designing Powerful Visuals for Engaging Learning
tmiket
1
440
Tell your own story through comics
letsgokoyo
1
990
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