@developersteve #APIDaysAU
OpenResty
Building APIs for scale with
@developersteve #APIDaysAU
@developersteve #APIDaysAU
Steven Cooper
Sniip CTO
Developersteve.com
As Chief Technology Officer for Sniip Steven is
working closely to help scale the platform and
creating new innovative ways for consumers to pay.
With Sniip’s frictionless and easy to use application
he is working with government agencies, councils
and utility companies to implement the technology.
@developersteve #APIDaysAU
About
US
Sniip is a disruptive force in the payment space
It is the first of its kind in Australia as it is a
mobile payment application built not around
a bank or payment brand, but rather,
around the consumer.
About Sniip
Where it started
@developersteve #APIDaysAU
SCAN CHECKOUT
How it Works
The easy way to pay
PIN
@developersteve #APIDaysAU
Other “solutions”
Such advanced technology
@developersteve #APIDaysAU
@developersteve #APIDaysAU
Our Legacy Stack
It has to start somewhere
@developersteve #APIDaysAU
@developersteve #APIDaysAU
<3 AWS
@developersteve #APIDaysAU
Laravel API’s
Php framework
@developersteve #APIDaysAU
PHP is a framework
http://phpthewrongway.com
@developersteve #APIDaysAU
Mysql Schema
Mysql architecture
@developersteve #APIDaysAU
Our Strategy
Rebuilding for scale, elasticity and futureproofing
UX/UI
Create a user
experience that
futureproofs the UX
Functionality
Building relevant
functionality that allows
for scale
Developer Portal
API’s and
Documentation built for
internal and external
User Engagement
Ensuring we build how
users want to use our
platform
@developersteve #APIDaysAU
@developersteve #APIDaysAU
The Stack
Openresty
@developersteve #APIDaysAU
OpenResty
A fusion between Nginx and Lua
@developersteve #APIDaysAU
OpenResty Market Share
Used by nearly half a million websites
https://wappalyzer.com/categories/web-servers
@developersteve #APIDaysAU
Powering Tumblr
Used by high traffic sites
https://news.netcraft.com/archives/2016/09/19/september-2016-web-server-survey.html
@developersteve #APIDaysAU
OpenResty Libs
https://devstev.es/orlibs
@developersteve #APIDaysAU
OpenResty Machine Learning
http://torch.ch/
@developersteve #APIDaysAU
<3 Nginx
Nginx is awesome
@developersteve #APIDaysAU
Lua is back … again
Cant beat a classic
@developersteve #APIDaysAU
Corona SDK
Cross platform mobile
@developersteve #APIDaysAU
Let’s Encrypt
Automatically renewable SSL
@developersteve #APIDaysAU
Auto renew SSL
https://devstev.es/autossl
@developersteve #APIDaysAU
Auto renew SSL
https://devstev.es/autossl2
@developersteve #APIDaysAU
PCI DSS 3.2
Payment Card Industry Data Security Standard
@developersteve #APIDaysAU
Implement TLS
A more secure connection
TLS 1.0
TLS 1.1
TLS 1.2
@developersteve #APIDaysAU
@developersteve #APIDaysAU
Configuration
Setting up the
@developersteve #APIDaysAU
Installing OpenResty
openresty.org
@developersteve #APIDaysAU
Openresty Nginx
Config nginx.conf
./configure
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-scgi-temp-path=/var/lib/nginx/scgi
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi
--lock-path=/var/lock/nginx.lock
--pid-path=/var/run/nginx.pid
@developersteve #APIDaysAU
Openresty Libraries
https://devstev.es/orlibs
--with-luajit --with-pcre-jit --with-debug
--with-http_auth_request_module
--with-http_geoip_module
--with-http_gzip_static_module
--with-http_ssl_module
--with-ipv6
--with-http_v2_module
--with-http_postgres_module
@developersteve #APIDaysAU
Make… Install…
@developersteve #APIDaysAU
@developersteve #APIDaysAU
Nginx.conf Loadbalance
Nginx as per normal
@developersteve #APIDaysAU
Nginx.conf Basic
Nginx as per normal
worker_processes auto;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
}
}
@developersteve #APIDaysAU
Nginx.conf SSL/TLS
Nginx as per normal
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on; ssl_ciphers
"EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AE
S256+EDH";ssl_ecdh_curve secp384r1;
ssl_session_timeout 1d;ssl_session_cache
shared:SSL:10m;ssl_session_tickets off;ssl_stapling
on;ssl_stapling_verify on;listen 443 ssl http2;listen [::]:443
ssl http2;ssl_certificate
/etc/letsencrypt/live/website.com/fullchain.pem;ssl_certificat
e_key
/etc/letsencrypt/live/website.com/privkey.pem;add_header
X-Frame-Options DENY;add_header X-Content-Type-
Options nosniff;add_header X-XSS-Protection "1;
mode=block";
@developersteve #APIDaysAU
@developersteve #APIDaysAU
Nginx.conf additionals
Nginx setup
http {
init_by_lua ’
json = require "cjson";
';
}
@developersteve #APIDaysAU
Nginx.conf Routes
Routing like a boss
location / {
content_by_lua_file ”./hello.lua";
}
@developersteve #APIDaysAU
Calling in Lua
helloworl.lua
local cjson = require("cjson")
ngx.status = ngx.HTTP_OK
ngx.header.content_type = "application/json; charset=utf-8”
ngx.say(cjson.encode({ hello = "world" }))
return ngx.exit(ngx.HTTP_OK)
@developersteve #APIDaysAU
Run OpenResty Run
Fingers crossed
nginx -p `pwd`/ -c nginx.conf
@developersteve #APIDaysAU
Nginx.conf Routes
Routing like a boss
location / {
content_by_lua_file ”./hello.lua";
}
location ~/status {
content_by_lua_file ”./status.lua";
}
@developersteve #APIDaysAU
Calling in Lua
Return a status
local cjson = require("cjson")
ngx.status = ngx.HTTP_OK
ngx.header.content_type = "application/json; charset=utf-8”
ngx.say(cjson.encode({ status = true }))
return ngx.exit(ngx.HTTP_OK)
@developersteve #APIDaysAU
@developersteve #APIDaysAU
Template Engine Lua
https://devstev.es/luatemp
@developersteve #APIDaysAU
OpenResty Snippets
https://devstev.es/luasnip
@developersteve #APIDaysAU
Load Testing
I feel the need for speed
@developersteve #APIDaysAU
@developersteve #APIDaysAU
@developersteve #APIDaysAU
BlitzIO
https://blitz.io
@developersteve #APIDaysAU
Legacy
@developersteve #APIDaysAU
OpenResty
@developersteve #APIDaysAU
Response Times
Left is legacy – Right is new
OpenRestyLegacy
@developersteve #APIDaysAU
Hit Rate
Left is legacy – Right is new
OpenRestyLegacy
@developersteve #APIDaysAU
@developersteve #APIDaysAU
Reading
Recommended
@developersteve #APIDaysAU
Designing robust API’s
https://devstev.es/api1
@developersteve #APIDaysAU
What is OpenResty
https://devstev.es/api2
@developersteve #APIDaysAU
Moltin OpenResty
https://devstev.es/api3
@developersteve #APIDaysAU
Thanks
Questions? Comments?
@developersteve #APIDaysAU
8-Bit Open Source
@developersteve #APIDaysAU
Drop Microphone
Walk off stage

APIDays Australia - Openresty for scale

Editor's Notes

  • #2 So awesome to be speaking at my 5th ApiDays in Australia I still remember speaking at the first one in Sydney and its been awesome seeing it grow like it has in Australia and New Zealand
  • #3 Previous to my current role I was an evangelist with paypal and xero travelling nearly half a million kms speaking at conferences throughout Asia pacific
  • #4 About us The platform Tech debt is unavoidable – from the moment you start that first git repo to the time you deploy the clock is ticking Why openresty openresty http2 Lets encrypt Speed tests Clustering Redis
  • #10 Tech debt is unavoidable
  • #11 AWS is awesome, however theres some things I don’t like
  • #20 TLS 1.2 enable
  • #33 Download and build form source ./configure –j2 make –j2 Sudo make install
  • #34 Make install nginx with configuration, you can configure all the usual default settings as part of the nginx stack
  • #35 At this point you can also start calling in all the openresty libraries that youll need inside your apis, like http2 posgres or database connections
  • #36 Load balancing
  • #37 Load balancing
  • #41 Load balancing
  • #42 Initiate common lua requirements inside the nginx.conf block, this saves time having to call them into the lua files later
  • #48 Comparing apples to oranges
  • #52 Comparing apples to oranges
  • #53 TLS 1.0
  • #55 T2 small instance with 2 gigs of memory
  • #56 Ec2 micro – 500 meg mem and a 2 gig swapspace
  • #59 TLS 1.0