+ All Categories
Home > Documents > PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy...

PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy...

Date post: 20-Mar-2018
Category:
Upload: duongthien
View: 223 times
Download: 4 times
Share this document with a friend
50
Coding PopVote
Transcript
Page 1: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Coding PopVote

Page 2: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Patrick CheungPopVote backend developer

Page 3: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Why am I here?

Page 4: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

highest throughput in any second

47 votes in 1 second

Page 5: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

first voting day (20 June)

Page 6: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

may include duplicated votes

> 70% votes casted in less then 180 seconds

Page 7: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation
Page 8: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

puppetredis

tornado

python

mysql

statsdfluentd

supervisord

fabric

flask

boto

pycrypto

sqlalchemy

itsdangerous

pycaptcha

uwsginginx

ubuntu

mcollective

csshx

r10k

json

jwt

async iouuid pubsub

vagrant

Page 9: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

• 100% written in Python

• 18,000 line of code

• API Server

• Ballot Server

• Control Panel

Page 10: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation
Page 11: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Client

Page 12: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps

Page 13: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps API

Server

firewall

1. captcha 2. verify 3. submit

Page 14: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps

redis in-memorytransient data

APIServer

firewall

1. captcha 2. verify 3. submit

Page 15: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps https

redis in-memorytransient data

APIServer

firewall

1. captcha 2. verify 3. submit

Page 16: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps https

Ballot Server

firewall

redis in-memorytransient data

APIServer

firewall

1. captcha 2. verify 3. submit

Page 17: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps https

Ballot Server

firewall

redis in-memorytransient data MySQL ballot data

APIServer

firewall

1. captcha 2. verify 3. submit

Page 18: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps https

Ballot Server

firewall

Station Server

https

redis in-memorytransient data MySQL ballot data

APIServer

firewall

1. captcha 2. verify 3. submit

Page 19: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

developing a system

Page 20: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

developing a system

• short development timeframe

Page 21: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

developing a system

• short development timeframe

• system load gradually increase

Page 22: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

developing a system

• short development timeframe

• system load gradually increase

• optimise system with real load

Page 23: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

developing a system

• short development timeframe

• system load gradually increase

• optimise system with real load

• not mission critical

Page 24: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

• short development timeframe

• system load gradually increase

• optimise system with real load

• not mission critical

developing popvote

Page 25: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

• short development timeframe

• system load gradually increase

• optimise system with real load

• not mission critical

developing popvote

Page 26: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

• short development timeframe

• system load gradually increase

• optimise system with real load

• not mission critical

developing popvote

Page 27: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

• short development timeframe

• system load gradually increase

• optimise system with real load

• not mission critical

developing popvote

Page 28: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Public-facing web servers do not have access to the database

Page 29: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps httpsAPI

Server

firewall

Ballot Server

firewall

Station Server

https

MySQL ballot data

Page 30: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Clienthttps httpsAPI

Server

firewall

Ballot Server

firewall

Station Server

https

MySQL ballot data

Page 31: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Users are notified immediately when they are successfully verified

Page 32: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation
Page 33: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

Page 34: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

Got the SMS yet?

Page 35: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

Not yet!Come back in 30

seconds.Got the SMS yet?

Page 36: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation
Page 37: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

Page 38: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

Got the SMS yet?

Page 39: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

hold on…Got the SMS yet?

Page 40: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

hold on…Got the SMS yet?

SMS

Page 41: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

client server

Got the SMS yet?

SMS

Okay! You are verified.

Page 42: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

• Tornado Web Server and Async IO

• One thread can handle multiple clients at the same time

• Keep client connection opens

• Server subscribes to SMS events through redis

• Very fast response

Page 43: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Deploymenta mix of Puppet+CloudFormation

Page 44: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

• Cloud infrastructure created with CloudFormation

• Make use of EC2 Auto-scaling and Multi-AZ for high availability

• Application installed automatically when server start

• Automatically configured by Puppet Master

Page 45: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Design highlights

Page 46: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

API Design

• Client sends/receives

• Clear separation between client and server code

• Rapid client development

• Makes server simple

Page 47: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

API Design

• Client sends/receives

• Clear separation between client and server code

• Rapid client development

• Makes server simple

Page 48: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Stateless Design

• Avoid storing session state on server

• Session state exchanged with client in encrypted form

• Good for privacy

• Good for server performance and operation

Page 49: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Duplicate votes

• Duplicate vote checked at the very last step

• Vote is recorded if not duplicate

• Minimise participation checking by attacker

• Makes web server simple

• Database access restricted to ballot server

Page 50: PopVote - University of Hong Kong · PDF filefabric flask boto pycrypto sqlalchemy itsdangerous pycaptcha uwsgi ... developing popvote ... CloudFormation

Further Improvement

• Diversify choice of cloud providers

• Application containment using Docker

• Consolidate server resources


Recommended