erlang for the web - erlang-factory.com · erlang for the web david de boer @ddeboer_nl. let’s...

53
Erlang for the Web David de Boer @ddeboer_nl

Upload: others

Post on 19-Oct-2019

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Erlang for the Web

David de Boer@ddeboer_nl

Page 2: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Let’s build a website

Page 3: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 4: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Simple blog

Images

SEO

Letsencrypt

Multilingual

CMS

Page 5: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Simple blog

Images

SEO

Letsencrypt

Multilingual

CMS

Search

Access control

E-mail

WebSockets

S3

Caching

Page 6: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 7: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 8: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 9: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 10: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 11: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 12: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 13: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 14: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

CMSweb framework

Page 15: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

It’s Erlang!

Natural async

Long-lived processes (WebSockets)

Fault tolerance

In-memory caching

Less waste

Page 16: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

And…

Controllerless pages

Dynamic routing

MQTT with UBF

Built-in e-mail

And more…

Page 17: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Principles

Page 18: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Powerful templates

Aggressive caching

Include batteries

Page 19: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

<h1>{{ id.title }}</h1>

<ul>

{% for article in m.search[{query hasobject=[id, 'author']}] %}

<li>{{ article.title }}</li>

{% endfor %}

</ul>

Page 20: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

{% live template="user-status.tpl"

topic="~pagesession/session"

target="user-status" %}

user-status.tpl:

{% if m.acl.user %}

Greetings user {{ m.acl.user.name_first }}!

{% else %}

Hello anonymous! Why not log in so we can better track you?

{% endif %}

Subscribe to session MQTT topic

Access check

Page 21: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Small teams, large impact

Page 22: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 23: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 24: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 25: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 26: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 27: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Data vision

Page 28: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 29: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 30: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 31: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 32: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 33: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

$ docker run \

-v `pwd`:/opt/zotonic/user/sites \

-p 8443:8443 zotonic/zotonic-heavy

Page 34: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

{% for result in m.search[{recommend hasobject=[id, 'author']}] as results %}

-module(yoursite).

-include_lib("zotonic_core/include/zotonic.hrl").

observe_search_query(#search_query{search = {recommend, Args}} = Query, Context) ->

recommend:search(Query, Context);

observe_search_query(_, _) ->

undefined.next observer, based on prio

Page 35: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

-module(yoursite).

-include_lib("zotonic_core/include/zotonic.hrl").

observe_acl_is_allowed(#acl_is_allowed{action = view, object = Id}, Context) ->

case m_rsc:is_a(Id, recommendation, Context) of

true ->

custom_acl:can_view_recommendation(Id, Context);

false ->

undefined

end;

observe_acl_is_allowed(#acl_is_allowed{}, _Context) ->

undefined.

next observer

Page 36: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

16 releasesAnd counting...

Page 37: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 38: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

1.0

Page 39: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 40: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 41: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

We changed a lot

Page 42: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Cowboy

Fixed bottlenecks

The Great Binarification

Dispatch Compiler

Template Compiler

Page 43: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 44: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 45: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Some history

2009 2010 2011 2014 2017

Zotonic 0.1.0 NPM Elixir Hex Zotonic 1.0

Erlang R13B03 Erlang 20

Rebar

Page 46: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 47: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 48: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 49: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Zotonic

As application server

site modsite

Page 50: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

As dependency

Site

Core Rsc ACL

Template Compiler

Dispatch Compiler

Depcache

Page 51: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 52: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog
Page 53: Erlang for the Web - erlang-factory.com · Erlang for the Web David de Boer @ddeboer_nl. Let’s build a website. Simple blog Images SEO Letsencrypt Multilingual CMS. Simple blog

Thanks!

David de Boer@ddeboer_nl

zotonic.com