https://iximiuz.com/ Ivan Velichko on Containers, Kubernetes, and Backend Development 2021-07-19T17:06:25.305Z awesome Ivan Velichko [email protected] https://iximiuz.com/en/about/ Learning Containers, Kubernetes, and Backend Development with Ivan Velichko https://iximiuz.com/favicon.ico All rights reserved 2022, Ivan Velichko <![CDATA[Writing Web Server in Python: sockets]]> https://iximiuz.com/en/posts/writing-web-server-in-python-sockets/ 2020-12-27T00:00:00.000Z <![CDATA[Explaining basics of TCP/IP stack and implementing simple TCP echo server in Python. How to create server socket? Accept client connection? How to get client socket IP and port?]]> <![CDATA[What is a web server? Let's start by answering the question: _What is a web server_? First off, it's a server (no pun intended). A server is a process [sic] serving clients. Surprisingly or not, a server has nothing to do with hardware. It's just a regular piece of software run by an operating system. Like most other programs around, a server gets some data on its input, transforms data in accordance with some business logic, and then produces some output data. In the case of a _web server_, the input and output happen over the network via _Hypertext Transfer Protocol (HTTP)_. For a web server, the input consists of HTTP requests from its clients - web browsers, mobile applications, IoT devices, or even other web services. And the output consists of HTTP responses, oftentimes in form of HTML pages, but other formats are also supported. ]]> Ivan Velichko [email protected] https://iximiuz.com/en/about/ <![CDATA[How to use Flask with gevent (uWSGI and Gunicorn editions)]]> https://iximiuz.com/en/posts/flask-gevent-tutorial/ 2019-12-27T00:00:00.000Z <![CDATA[Create asynchronous Flask application and run it with uWSGI or Gunicorn behind Nginx reverse proxy.]]> <![CDATA[ Python is booming and Flask is a pretty popular web-framework nowadays. Probably, quite some new projects are being started in Flask. But people should be aware, it's synchronous by design and ASGI is not a thing yet. So, if someday you realize that your project really needs asynchronous I/O but you already have a considerable codebase on top of Flask, this tutorial is for you. The charming gevent library will enable you to keep using Flask while start benefiting from all the I/O being asynchronous. In the tutorial we will see: - How to monkey patch a Flask app to make it asynchronous w/o changing its code. - How to run the patched application using gevent.pywsgi application server. - How to run the patched application using Gunicorn application server. - How to run the patched application using uWSGI application server. - How to configure Nginx proxy in front of the application server. ]]> Ivan Velichko [email protected] https://iximiuz.com/en/about/ <![CDATA[Explaining async/await in 200 lines of code]]> https://iximiuz.com/en/posts/from-callback-hell-to-async-await-heaven/ 2019-05-02T00:00:00.000Z <![CDATA[What are the callback alternatives? From callback to promises. From promises to async/await. Implementing async/await using generators.]]> <![CDATA[ In the previous article, we learned how to implement a simple but workable event loop. However, programs which are supposed to be run by the event loop are full of callbacks. This is the usual problem of _event-loop-driven environments_. When business logic becomes reasonably complicated, callbacks make program's code hardly readable and painfully maintainable. **And the callback hell begins!** There is plenty of ways to deal with the artificial complexity arose due to callbacks, but the most impressive one is to make the code ~~_great_~~ _flat_ again. And by _flat_, I mean callback-less and synchronous-like. Usually, it's done by introducing `async/await` syntactic feature. But every high-level abstraction is built on top of some basic and fundamental ideas. Let's check the `async/await` sugar out and see what exactly happens under the hood. ]]> Ivan Velichko [email protected] https://iximiuz.com/en/about/ <![CDATA[Explaining event loop in 100 lines of code]]> https://iximiuz.com/en/posts/explain-event-loop-in-100-lines-of-code/ 2019-04-25T00:00:00.000Z <![CDATA[What is an event loop? What event loops are suitable for? How to implement an event loop in Python in less than 100 lines of code.]]> <![CDATA[ There is plenty of articles out there about the event loop. However, as a software engineer, I prefer to read code, not text. And there is no better way of learning a new concept than implementing it yourself. So, let's try to grasp the idea of the event loop by coding a new one. In the article, we will try to describe the idea of the event loop in general, not a specific implementation of the event loop in Node.js or Python, or some other language/library. ]]> Ivan Velichko [email protected] https://iximiuz.com/en/about/ <![CDATA[Save the day with gevent]]> https://iximiuz.com/en/posts/save-the-day-with-gevent/ 2019-04-17T00:00:00.000Z <![CDATA[Do you wish you had started using async I/O before these thousands of lines of code in your flask app? Do you think it's too late to switch? Gevent to the rescue!]]> <![CDATA[ One day you were hired by a startup to build yet another web site. The problem sounded similar to numerous back-ends you had been doing before. So, you decided to move with _python_ to be conservative enough and pick _flask_ to be lightweight but yet powerful enough. Nobody was fired for starting things in python, wise man's choice. ]]> Ivan Velichko [email protected] https://iximiuz.com/en/about/