Send Balls Into Orbit with
Python3, AsyncIO,
WebSockets, Redis and React
Taras Lyapun, KhmelnitskiyPy#1
About me
- Organizer of KhmelnytskyiPy

- CTO at Turfmapp.com

- Founder of Four-Eyes.IO
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
What is this story
about?
- We had everything for players
before game

- But we didn’t have anything for
game

- Introduce - Mini Challenges
Send Balls Into Orbit with Python3, AsyncIO,
WebSockets, Redis and React
Send Balls Into Orbit with Python3, AsyncIO,
WebSockets, Redis and React
Python
• Simple

• Maintainable

• Powerful

• Great syntax

• Can be used for anything:

• web

• network

• math

• ML

• NLP

• etc

• Great community!
Send Balls Into Orbit with Python3, AsyncIO,
WebSockets, Redis and React
Python3
• New, modern version of
Language

• A lot of improvements

• Unicode everywhere

• Lazy by default

• One more thing…
Send Balls Into Orbit with Python3, AsyncIO,
WebSockets, Redis 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
Introduction to Asynchronous Programming
http://cs.brown.edu/courses/cs168/f12/handouts/async.pdf
PEP-0492
PEP-0492
Send Balls Into Orbit with Python3, AsyncIO,
WebSockets, Redis 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
aiohttp
Send Balls Into Orbit with Python3, AsyncIO,
WebSockets, Redis 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
asyncio-redis
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
Send Balls Into Orbit with Python3, AsyncIO,
WebSockets, Redis and React
Thanks!

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

  • 1.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React Taras Lyapun, KhmelnitskiyPy#1
  • 2.
    About me - Organizerof KhmelnytskyiPy - CTO at Turfmapp.com - Founder of Four-Eyes.IO
  • 3.
    Turfmapp.com • Find placesand 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
  • 4.
    What is thisstory about? - We had everything for players before game - But we didn’t have anything for game - Introduce - Mini Challenges
  • 5.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React
  • 6.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React
  • 7.
    Python • Simple • Maintainable •Powerful • Great syntax • Can be used for anything: • web • network • math • ML • NLP • etc • Great community!
  • 8.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React
  • 9.
    Python3 • New, modernversion of Language • A lot of improvements • Unicode everywhere • Lazy by default • One more thing…
  • 10.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React
  • 11.
    AsyncIO • Allows youto 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
  • 12.
    Introduction to AsynchronousProgramming http://cs.brown.edu/courses/cs168/f12/handouts/async.pdf
  • 13.
  • 14.
  • 15.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React
  • 16.
    WebSockets • Full-duplex communicationchannel 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
  • 17.
  • 18.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React
  • 19.
    Redis • Advanced Key-Valuecache and store • Strings, hashes, lists, sets, etc • Publish Subscribe • High performance with good enough level of persistency for this task
  • 20.
  • 21.
    Another Decisions • Alwayssend 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
  • 22.
    Send Balls IntoOrbit with Python3, AsyncIO, WebSockets, Redis and React
  • 26.