/
index.html
231 lines (222 loc) · 10.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Clojure Backend Services</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/night.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h2>Clojure Backend Services from the Trenches</h2>
<p>
<small>By <a href="http://medium.com/@mhjort">Markus Hjort</a> / <a href="http://twitter.com/mhjort">@mhjort</a></small>
</p>
<p>
<small><a href="http://adtile.me">Adtile Technologies</a></small>
</p>
</section>
<section>
<section>
<h3>Q: Clojure at work?</h3>
<img src="img/clojure_at_work.png"/>
</section>
<section>
<h3>A: My work 2013-2017</h3>
<h4>Polyglot backend microservices à la DevOps</h4>
<ul>
<li>Yle: Clojure (JVM), Scala, Node.js</li>
<li>Adtile: Clojure (JVM), Rails, Node.js</li>
</ul>
</section>
</section>
<section>
<section>
<h2>From the trenches</h2>
</section>
<section>
<h3>Q: Why JVM?</h3>
</section>
<section>
<h3>A: 222852 Java libraries in GitHub (Q4/14)</h3>
<p><small>http://githut.info</small></p>
</section>
<section>
<h3>A: Embrace the host language</h3>
<pre class="clojure"><code data-trim data-noescape>
(doto (AmazonS3Client.)
(.withEndpoint custom-end-point)
(.setS3ClientOptions (-> (S3ClientOptions.)
(.withPathStyleAccess true)))))
</code></pre>
<!-- Calling Clojure code from Java -->
</section>
<section>
<h3>Monitoring & profiling</h3>
<img src="img/jconsole.png" width="80%"/>
</section>
<section>
<h3>Parallelism</h3>
<pre class="clojure"><code data-trim data-noescape>
(pmap process-object objects)]) # JVM Thread pool
</code></pre>
<pre class="clojure"><code data-trim data-noescape>
(r/fold merge-counts
count-words
(s/split text #"\s+"))) # Java7 Fork/Join
</code></pre>
</section>
<section>
<h3>Robust Tech for <span style="text-decoration:line-through;">Grumpy Old</span> Senior Developers</h3>
</section>
<section>
<h3>Q: How do we run our code?</h3>
</section>
<section>
<h3>Option 1: Uberjar with embedded http-kit or Jetty</h3>
</section>
<section>
<h3>Option 2: AWS Lambda function</h3>
<img src="img/AWS_Simple_Icons_Compute_AWSLambda.svg"/>
</section>
<section>
<h3>Q: How do we select the libraries we use?</h3>
</section>
<section>
<h3>Prio 1: clojure.core</h3>
</section>
<section>
<h3>Prio 2: Native Clojure libraries</h3>
<h4>e.g. ring, hiccup</h4>
</section>
<section>
<h3>Prio 3: Clojure libraries with minimal dependencies</h3>
<h4>e.g. http-kit</h4>
</section>
<section>
<h3>Prio 4: Simple wrappers around Java API</h3>
<h4>e.g. clj-http, clj-time</h4>
<pre class="clojure"><code data-trim data-noescape>
[clj-http "3.4.1"]
[commons-codec "1.10"]
[commons-io "2.5"]
[org.apache.httpcomponents/httpasyncclient "4.1.2"]
[org.apache.httpcomponents/httpcore-nio "4.4.5"]
[org.apache.httpcomponents/httpclient "4.5.2"]
[commons-logging "1.2"]
[org.apache.httpcomponents/httpcore "4.4.5"]
[org.apache.httpcomponents/httpmime "4.5.2"]
[potemkin "0.4.3"]
[clj-tuple "0.2.2"]
[riddley "0.1.12"]
[slingshot "0.12.2"]
</code></pre>
</section>
<section>
<h3>Prio 5: Java APIs directly</h3>
<h4>e.g AWS Java SDK instead of Amazonica</h4>
<img src="img/amazonica.png" width="60%"/>
</section>
<section>
<h3>Q: How do we test Clojure code?</h3>
</section>
<section>
<h3>clojure.test</h3>
</section>
<section>
<h3>Stubbing using with-redefs</h3>
<pre class="clojure"><code data-trim data-noescape>
(deftest returns-error-when-replication-fails
(with-redefs [s3/upload (fn [& _]
(throw (Exception. "Simulated")))]
(run-the-test)))
</code></pre>
</section>
<section>
<h3>Q: How do we maintain large code bases without types?</h3>
</section>
<section>
<h3>A: We don't :D</h3>
<img src="img/acrobate.jpg"/>
</section>
<section>
<h3>Typesystem not mature enough</h3>
<img src="img/typed_clojure.png" style="background-color: #cccccc;"/>
</section>
<section>
<h3>With microservices it is more important to specify and validate in RUNTIME inputs and outputs of services</h3>
</section>
<section>
<h3>Schema validation</h3>
<img src="img/prismatic_schema.png" style="background-color: #cccccc;"/>
</section>
<section>
<h3>Q: How do we manage state?</h3>
</section>
<section>
<h3>atom(s)</h3>
<pre class="clojure"><code data-trim data-noescape>
(defonce ads (atom {}))
(defn update-state []
(try
(reset! ads (get-all-ads))
(info "Updated ads data with" (count @ads) "ads.")
(catch Exception e
(error e "Failed to update ads"))))
</code></pre>
</section>
</section>
<section>
<section>
<h2>Clojure is an opinionated language</h2>
</section>
<section>
<h2>Maybe you should be too</h2>
<img src="img/question.png" width="30%"/>
</section>
<section>
<h2>Thanks!</h2>
<img src="img/mhjort.jpg"/>
<h4>@mhjort</h4>
<ul>
<lh><small>Contributions</small></lh>
<li><small>By Symbol question.svg: Erin Silversmith derivative work: Kayau (Symbol question.svg:) [Public domain], via Wikimedia Commons:</small></li>
<li><small>By Muriel blondeau (collection de l'auteur) [CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons</small></li>
</ul>
</section>
</section>
</div>
</div>
<div style="position: absolute; bottom: 50px; right: 120px;">
<svg width="92" height="31" viewBox="0 0 277 94" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><path id="a" d="M3.4 53.3C-1.2 39.7 6.2 21 35.4 19c20.8-1 30.3 11 30.3 11s5.5-11 27-11c0 .3-4-18.8 17-18.7 14.3 0 19 6.8 19 6.8s11.6-5 25.8 1c1-.6 3.3-7 16.7-6.5 10 0 14 2 14 2s6.2-2 14.4-2c14 0 17.4 2.7 17.4 27.3 3.4-6 18.4-9.7 24.3-9.7 21-1 35.4 20 35.4 35.3 0 15.4-6.8 39.2-35.4 39.2-19.3-.5-25-8.7-25-8.7s-3 8-14.7 8c-7.3.2-11.2 0-16.3-2.5-4.6 3.4-15.5 4.2-22.8.8-2.6 1.6-22 7-34.2-4.6C121 98 102.5 91 102.5 91S85.2 99 69.8 87c-7.2 6.6-11 8-28.2 4.3-42 12.4-45-25-38.2-37.7z"/><path d="M13.7 47.3c.2-3.3 1-6 2.4-8 1.5-2.2 3.3-4 5.5-5.2 2.2-1.2 4.7-2 7.4-2.7 2.7-.5 5.4-.8 8.2-.8 2.5 0 5 .2 7.7.5 2.5.4 4.8 1 7 2 2 1 4 2.6 5.2 4.4 1.4 2 2 4.3 2 7.4v26c0 2.3.2 4.5.4 6.5.3 2 .7 3.7 1.4 4.7H47l-.6-2.4-.3-2.4c-2 2.2-4.7 3.8-7.7 4.7-3 .8-6 1.3-9 1.3-2.5 0-4.7-.3-6.8-1-2-.5-4-1.4-5.4-2.6-1.5-1.3-2.7-2.8-3.6-4.7-1-2-1.3-4-1.3-6.7 0-2.8.6-5.2 1.6-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2.6-1.2 4.7-3.2 6.3-6h.2zm41-43.7V16.7h-13.8v15h-8.5v9.3h8.4v29.7c0 2.5.3 4.5 1 6 1 1.6 2 2.8 3.6 3.7 1.4.8 3 1.4 5 1.6 2 .3 4 .5 6 .5h4.3l3.7-.5V71.3c-.6.2-1.3.3-2 .3h-2.2c-2.4 0-4-.3-4.7-1-.8-.8-1.2-2.4-1.2-4.7V41h10v-9h-10zm31.8-8V12.8h-13.8V24h13.8zm-13.8 8v50h13.8V32h-13.8zm26-19.3V82h13.8V12.7h-13.8zM251 51.5h-22.3c0-1 .3-2 .7-3.3.3-1.2 1-2.3 1.8-3.4 1-1 2-2 3.5-2.8 1.4-.8 3.3-1 5.5-1 3.3 0 5.8.8 7.5 2.6 1.6 1.8 2.8 4.4 3.4 8zm-22.3 8.8H265c.2-4-.2-7.6-1-11.2-1-3.4-2.4-6.6-4.5-9.4-2-2.8-4.6-5-7.8-6.6-3.2-1.7-7-2.5-11-2.5s-7.4.7-10.6 2c-3 1.4-5.7 3.2-8 5.6-2.2 2.5-4 5.3-5.2 8.5-1.2 3.2-1.8 6.7-1.8 10.5 0 4 .6 7.4 1.7 10.6 1.2 3.3 3 6 5 8.4 2.3 2.3 5 4 8.2 5.4 3 1.2 6.6 2 10.6 2 5.7 0 10.5-1.4 14.5-4s7-7 9-13h-12c-.5 1.6-1.8 3-3.8 4.5-2 1.3-4.4 2-7.2 2-3.8 0-6.8-1-9-3-2-2-3-5.3-3.3-9.7z" id="b"/></defs><g fill="none" fill-rule="evenodd"><use fill-opacity=".2" fill="#000" xlink:href="#a"/><use xlink:href="#a"/><g><use fill="#FFF" xlink:href="#b"/><use xlink:href="#b"/></g></g><text opacity="0">adtile</text></svg>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
history: true,
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>