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
Building a sustainable architecture
Search
Marcelo Piva
October 26, 2019
Programming
120
1
Share
Building a sustainable architecture
Marcelo Piva
October 26, 2019
More Decks by Marcelo Piva
See All by Marcelo Piva
Maintaining consistency in distributed systems with an effect machine
mpivaa
1
290
Fun with Monads
mpivaa
2
200
Go Pure with ClojureScript
mpivaa
2
190
Other Decks in Programming
See All in Programming
[PHPerKaigi 2026]PHPerKaigi2025の企画CodeGolfが最高すぎて社内で内製して半年運営して得た内製と運営の知見
ikezoemakoto
0
340
今年もTECHSCOREブログを書き続けます!
hiraoku101
0
230
ファインチューニングせずメインコンペを解く方法
pokutuna
0
280
How Swift's Type System Guides AI Agents
koher
0
190
PHPで TLSのプロトコルを実装してみるをもう一度しゃべりたい
higaki_program
0
180
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
140
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
190
Going Multiplatform with Your Android App (Android Makers 2026)
zsmb
2
350
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
320
脱 雰囲気実装!AgentCoreを良い感じにWEBアプリケーションに組み込むために
takuyay0ne
3
440
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
860
Vibe하게 만드는 Flutter GenUI App With ADK , 박제창, BWAI Incheon 2026
itsmedreamwalker
0
540
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.2k
Code Reviewing Like a Champion
maltzj
528
40k
We Have a Design System, Now What?
morganepeng
55
8.1k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Tell your own story through comics
letsgokoyo
1
890
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Building AI with AI
inesmontani
PRO
1
870
What does AI have to do with Human Rights?
axbom
PRO
1
2.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.1k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
190
Raft: Consensus for Rubyists
vanstee
141
7.4k
Transcript
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