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
Building a sustainable architecture
Search
Marcelo Piva
October 26, 2019
Programming
130
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Building a sustainable architecture
Marcelo Piva
October 26, 2019
Transcript
98 slides
Building a sustainable architecture
Marcelo Piva Software Engineer @ Nubank @mpivaa github.com/mpivaa instagram.com/mah.piva
Carolina Pascale Campos Software Engineer @ Nubank @CarolinaPascale github.com/carolpc instagram.com/carolpc
books, coffee, running
motivation
None
smooth learning curve shipped code to production
almost no guidance
why?
None
300+ engineers 300+ services 15M customers
None
patterns among services
functional programming tests △ hexagonal architecture ⬡
functional programming
fp is about pure functions
fp is about referential transparency
��
Consistency Predictability Safety
we need to talk about side effects
not infecting your fp code with imperative code
limit the amount of imperative code
immutability vs mutability
pure functions + immutability
✅ easier to reason ✅ easier to debug
persistent data structures (copy-on-write)
Structural Sharing A =
Structural Sharing A = B =
Structural Sharing
Structural Sharing A
Structural Sharing B
focus on what matters
Class Object Instance Inheritance Polymorphism Abstract Factory Builder Factory Method
Object Pool Prototype Singleton Adapter Bridge Composite Decorator Facade Flyweight Private Class Data Proxy Chain of responsibility Command Interpreter Iterator Mediator Memento Null Object Observer State
None
eliminate shared state so order does not matter
don't have to set up anything up
be as functional as you can
tests △
confidence safety
feedback
accuracy
speed
reliability
✅ accuracy ✅ speed ✅ reliability
why highly testable code?
bonus: generative and property based testing
how to design our code?
high maintainability low tech debt
maintainability is a long term concept
first attempt: hexagonal architecture
inner layer: domain model
second layer: application
third layer: IO
separates business logic from IO
tests in isolation with mocks and stubs
dependency injection
first discover
hard things in OOP can be easy in FP (tests)
boundaries
third layer: IO
hexagonal architecture in FP is natural
push impure code to the boundaries
great discovery!
but, are we leveraring FP to its max?
services need to communicate
None
second layer with imperative code and side effects
why not imperative? harder to reason about harder to compose
harder to test slower feedback
why not imperative? harder to reason about harder to compose
harder to test slower feedback
why not imperative? (block! card datomic producer) ; =>
why not imperative? (defn block! [card datomic producer] (when (logic.card/can-block?
card) (let [locked-card (logic.card/block card)] (datomic.card/update! blocked-card datomic) (producer.card/status-changed! blocked-card producer))))
why not imperative? harder to reason about harder to compose
harder to test slower feedback
why not imperative? (defn block-all! [customer cards datomic producer] (doseq
[card cards] (block! card datomic producer)) (cards-blocked-notify! customer producer))
why not imperative? (defn block-all! [customer cards datomic producer] (doseq
[card cards] (block! card datomic producer)) (cards-blocked-notify! customer producer))
why not imperative? (defn block-all! [customer cards datomic producer] (doseq
[card cards] (block! card datomic producer)) (cards-blocked-notify! customer producer))
why not imperative? harder to reason about harder to compose
harder to test slower feedback
why not imperative? mocks & integration tests
None
Unit Integration E2E
why not imperative? harder to reason about harder to compose
harder to test slower feedback
None
❌ pure functions ❌ tests ❌ maintainability
let's try another approach
declaring effects on the return of functions
decouple decisions from effects
decouple intent from execution
(block card) ; => [{:effects/datoms [...] ; :effects/messages [...]}]
data as first class citizens
declarative
atomic operations
Global dependencies
Global dependencies Dependency injection
Dependency rejection Global dependencies Dependency injection
(defn block [card] (if (logic.card/can-block? card) (let [blocked-card (logic.card/block card)]
(-> e/empty-effects (effect.card/update blocked-card) (effect.card/status-changed blocked-card)))) e/empty-effects))
None
second layer without side effects
become more expressive
✅ pure functions ✅ tests ✅ maintainability
Thanks! We're hiring! https://grnh.se/5fc5f7e51 @mpivaa github.com/mpivaa instagram.com/mah.piva
More Decks by Marcelo Piva
See All by Marcelo Piva
Maintaining consistency in distributed systems with an effect machine
mpivaa
1
310
Fun with Monads
mpivaa
2
210
Go Pure with ClojureScript
mpivaa
2
200
Other Decks in Programming
See All in Programming
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
あなたはMCPの機能を、まだ知らない。
4geru
1
680
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
250
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
200
クラウドゲーミングのパフォーマンス最適化に挑む / Cloud Gaming Performance Tuning
vivion
0
360
仕様駆動開発入門 (何を作るかを先に決めて渡す) | 目指せ Kiro マスター 05
inariku
PRO
2
200
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
260
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
380
Kotlin JVM用に作られたライブラリのKMPを前提とした再設計
jsoizo
0
210
Snowflake Openflow Connector利用の勘所 / 20261024developersio2026tokyo-snowflake-openflow
kasacchiful
PRO
0
360
プロジェクトコードをキレイキレイしよう!暗黙的な参照を読み解く静的解析
ostk0069
0
220
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
270
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.2k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
[SF Ruby Conf 2025] Rails X
palkan
3
1.5k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
The Limits of Empathy - UXLibs8
cassininazir
2
790
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.9k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3.1k
So, you think you're a good person
axbom
PRO
2
2.3k