26
Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React Taras Lyapun, KhmelnitskiyPy#1

Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Embed Size (px)

Citation preview

Page 1: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO,

WebSockets, Redis and React Taras Lyapun, KhmelnitskiyPy#1

Page 2: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

About me

- Organizer of KhmelnytskyiPy- CTO at Turfmapp.com- Founder of Four-Eyes.IO

Page 3: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Turfmapp.com

• Find places and company to play soccer

• Like meetup.com, but soccer specific

• Like runkeeper.com, but for team sports

• Chicago based startup, with R&D office in Khmelnitskiy

Page 4: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

What is this story about?

- We had everything for players before game

- But we didn’t have anything for game

- Introduce - Mini Challenges

Page 5: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Page 6: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Page 7: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Python• Simple

• Maintainable

• Powerful

• Great syntax

• Can be used for anything:

• web

• network

• math

• ML

• NLP

• etc

• Great community!

Page 8: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Page 9: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Python3

• New, modern version of Language

• A lot of improvements

• Unicode everywhere

• Lazy by default

• One more thing…

Page 10: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Page 11: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

AsyncIO

• Allows you to start event loop, and execute your code asynchronously without additional libraries or frameworks

• So you can write your python code in both ways - sync and async, depends on your task

• Allows you easy support thousands persistent connections without threads overhead

• The best way to deal with network

Page 12: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Introduction to Asynchronous Programming

http://cs.brown.edu/courses/cs168/f12/handouts/async.pdf

Page 13: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

PEP-0492

Page 14: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

PEP-0492

Page 15: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Page 16: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

WebSockets

• Full-duplex communication channel over TCP

• Allow you to have real-time communication between server and client

• Supported by most browsers, but can be used also with any client (ios, android, whatever)

• aiohttp handles it well

Page 17: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

aiohttp

Page 18: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Page 19: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Redis

• Advanced Key-Value cache and store

• Strings, hashes, lists, sets, etc

• Publish Subscribe

• High performance with good enough level of persistency for this task

Page 20: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

asyncio-redis

Page 21: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Another Decisions

• Always send full state of game (everything needed to display screen), instead of sending incremental updates - easy and error prone

• How to deal with concurrency updates? - Some sort of optimistic locks

• Use JSON for easy extending protocol

• Process all data through Redis - for easy scale

Page 22: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Send Balls Into Orbit with Python3, AsyncIO, WebSockets, Redis and React

Page 23: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React
Page 24: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React
Page 25: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React
Page 26: Send Balls Into Orbit with Python3, AsyncIO, WebSockets and React

Thanks!