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
Gatelogic - Somewhat functional reactive framew...
Search
majek04
November 27, 2017
Programming
5.3k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Gatelogic - Somewhat functional reactive framework in Python
majek04
November 27, 2017
More Decks by majek04
See All by majek04
Keeloq_AD_2025__1_.pdf
majek04
0
44
BPF programmable socket lookup
majek04
0
680
Linux at Cloudflare
majek04
3
8.9k
DDoS Landscape
majek04
0
440
Inside Cloudbleed
majek04
3
3k
Golang sucks
majek04
21
53k
How Cloudflare deals with largest DDoS attacks?
majek04
2
3.6k
Why we chose Service Worker API
majek04
0
2.9k
IP Spoofing - DEFCON
majek04
1
1.1k
Other Decks in Programming
See All in Programming
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
4.9k
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
150
Why Laravel apps break—Mastering the fundamentals to keep them maintainable
kentaroutakeda
1
350
Swiftのレキシカルスコープ管理
kntkymt
0
220
AIで効率化できた業務・日常
ochtum
0
120
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
200
スマートグラスで並列バイブコーディング
hyshu
0
120
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
120
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
160
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.2k
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
120
OSもどきOS
arkw
0
480
Featured
See All Featured
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
230
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
840
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
160
Fireside Chat
paigeccino
42
3.9k
Mobile First: as difficult as doing things right
swwweet
225
10k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
The Cult of Friendly URLs
andyhume
79
6.9k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
We Have a Design System, Now What?
morganepeng
55
8.2k
Leo the Paperboy
mayatellez
7
1.8k
Transcript
Gatelogic FRP framework Marek Majkowski @majek04 ...200 lines of Python
I still regret...
Who we are? 2
Reverse proxy 3 Eyeball Reverse proxy Origin server • Optimizations
• Caching • DDoS protection • Security
Attacked 4
Signal 5 pretty analytics signal Operator switch switch switch
6 Signal
7
8 iptables rules mitigation servers command line Operator Mitigation
9 Mitigation
10 pretty analytics command line iptables mitigation signal Operator servers
switch switch switch
Copy-pasta 11
"Business logic" 12 iptables rules mitigation signal servers switch switch
switch ?
12 months later... 13
14 --ip=1.2.3.4 example.com --ip=1.2.3.4 example.com --qps=100 Business logic
15 --ip=1.2.3.4 example.com --qps=500 example.com = FREE | PAID Business
logic --ip=1.2.3.4 example.com
16 --ip=1.2.3.4 example.com --except www,n1,ns2 --qps=500 Business logic example.com subdomains:
(www, ns1, ns2) --ip=1.2.3.4 example.com example.com = FREE | PAID
17 Input Steam extra stream extra stream Output Stream Reactive
Rule
18 Reactive rule def dns_mitigation(attack, plan, subdomains, toggles): domain =
attack['domain'] if toggles['all_mitigations_disabled']: return qps = 100 if plan[domain] == 'business': qps = 500 mitigation = attack['description'] + \ ' --qps=%s' % qps + \ ' --except=%s'.join(subdomains[domain]) return mitigation
Subscriptions 19 def dns_mitigation(attack, plan, subdomains, toggles): domain = attack['domain']
if toggles['all_mitigations_disabled']: return qps = 100 if plan[domain] == 'business': qps = 500 mitigation = attack['description'] + \ ' --qps=%s' % qps + \ ' --except=%s'.join(subdomains[domain]) return mitigation
Business logic • Hard problem! • Multiple DB lookups •
Wait for operator confirmation • Critical path 20
Functional reactive programming 21
22
23 models - Excel
models - Materialized data 24 input output function 00:01h 23:59h
x
models - Signals 25
Pure FRP is useless • Weird language - (ELM anyone?)
• Fixed signal flow • Strictly no side-effects 26
Dirty FRP is awesome 27 • Weird language • Python
• Fixed signal flow • Attacks come and go, but patterns fixed • Strictly no side-effects • Dynamic "subscriptions", but idempotent
Prior art - Trellis 28
29
Gatelogic! 30 https://github.com/cloudflare/gatelogic
Gatelogic • Input - ReadableHub • update(full_data) • Processing -
ComputableHub • maintain(key, function) • unmaintain • Subscriptions - QueryHub • update(full_data) 31
32 { '00001': {ip:'1.2.3.4', port: 80, domain: 'bar.com', '00002': {ip:'1.2.3.5',
port: 80, domain: 'foo.com', ... } Input data - a dict
33 ReadableHub update { 'attack1': 'example.com', ... } update()
34 ComputableHub def on_hook(_, kind, k, row): if kind ==
'add': mitigations.maintain(k, action, row) if kind == 'delete': mitigations.unmaintain(k) subscribe(readable, on_hook) def action(row): return None 34 ReadableHub
35 OutputHub ComputableHub ?
36 OutputHub ComputableHub ReadableHub QueryHub ? database
37 OutputHub ComputableHub ReadableHub QueryHub X X X X X
X Materialized
38 def action(row, plan_hub, subdomain_hub, toggle_hub): domain = row.value if
not domain: return None if toggle_hub.get('all_mitigations_disabled').value != 'True': return None qps = 100 if plan_hub.get(domain).value in ('business', 'b'): qps = 500 sd = (subdomain_hub.get(domain).value or '').split(' ') mitigation = \ domain + \ ' --qps=%s ' % qps + \ ' '.join('--except=%s' % s for s in sd) return mitigation
It works! • Solid foundation! • Composable! • Scalable •
Maintainable • But: • no event loop • lacks higher-order abstractions 39
40
204 loc 41 marek@ubuntu-saucy:~/cloudflare/gatelogic/gatelogic$ cloc *py 3 text files. 3
unique files. 0 files ignored. http://cloc.sourceforge.net v 1.60 T=0.01 s (240.8 files/s, 23197.8 lines/s) ------------------------------------------------------------------------------- Language files blank comment code ------------------------------------------------------------------------------- Python 3 61 24 204 ------------------------------------------------------------------------------- SUM: 3 61 24 204 -------------------------------------------------------------------------------
Thanks! • FRP is grea • http://www.flapjax-lang.org/ • https://www.youtube.com/watch?v=mEvo6TVAf64 •
https://www.youtube.com/watch?v=Agu6jipKfYw 42 https://github.com/cloudflare/gatelogic marek@cloudflare.com @majek04