CoCo Corona Counter

[GitHub Repo]

Came alive on March 25, 2020

        When I wanted a primer on what micro-services were, I felt that building something meaningful would help me understand it better. This probably holds true for anything new you'd like to learn. Incidentally this urge to scratch the surface of microservices happened during the corona quarantine. The most straight forward thing that came to mind was to build an application that gets the number of corona cases in any country.

        So I scoured the internet on how to build a web service that was powered by other micro services. That's when I stumbled upon tornado. Now tornado is pretty cool because you could think of Tornado being to Python as what Node is to JavaScript. So if you're not comfortable with JS, and would like to spin up an asynchronous server-side implementation that can scale up tens of thousands of open connections, tornado is the way to go.

        I decided to name it CoCo, since "Corona Counter" was a mouthful. Anyways, for my web app, Tornado would constantly listen to changes in the browser url. When it does detect a change, it looks up the url routes defined in the tornado.web.Application object. Ofcourse it only does this after the server object is started up using "tornado.ioloop.IOLoop.current().start()". Once a "url route" matches, tornado delegates the responsibility of that url to a "handler" of the corresponding  micro-service. The handler then invokes the code that provides the core functionality of that micro-service. CoCo has two microservices, one which is responsible for scraping data to get the number of corona cases for a country, and the other, which takes care of rendering the front end stuff. This architecture is illustrated below, which should help you easily digest the functioning of CoCo.


Micro Service Architecture for CoCo
Micro-services architecture of CoCo


        Since all the work is delegated to two separted microservices, the "main file" ends up being minimal in code. The following code snippet should be self explanatory, and could give you a little more insight into the power of tornado.


if __name__ == '__main__':
    # specify routes and their respective handlers in tornado application object.
    app = tornado.web.Application([
        (r"/", HomePageHandler),
        (r"/displayCountryDetails/", ScrapeHandler, dict(scraper_obj = scraper_obj)),

        If any of the above "url routes" are 
        detected by tornado, it activates the
        corresponding micro web-service.
    # start the app


Check out this video to see CoCo in action!


Aaaandd, finally here's the link to the github repo if you wanna mess around with it.