I have built Zero: Fast and high performance Python RPC framework to build microservices

Zero is actually a RPC like framework that uses ZeroMQ under the hood for communication over tcp. That’s why it’s fast and super lightweight.

Without going into details let’s just get started, cause one of the philosophy behind Zero is Zero Learning C…


This content originally appeared on DEV Community and was authored by Azizul Haque Ananto

Zero is actually a RPC like framework that uses ZeroMQ under the hood for communication over tcp. That's why it's fast and super lightweight.

Without going into details let's just get started, cause one of the philosophy behind Zero is Zero Learning Curve ?

Example

Ensure Python 3.8+

  • Install Zero
pip install zeroapi

Sadly the zero package is already there ?

  • Create a server.py
from zero import ZeroServer

def echo(msg: str):
    return msg

async def hello_world():
    return "hello world"


if __name__ == "__main__":
    app = ZeroServer(port=5559)
    app.register_rpc(echo)
    app.register_rpc(hello_world)
    app.run()

Please note that server RPC methods' args are type hinted. Type hint is must in Zero server.

See the method type async or sync, doesn't matter. ?

  • Run it
python -m server
  • Call the rpc methods
from zero import ZeroClient

zero_client = ZeroClient("localhost", 5559)

def echo():
    resp = zero_client.call("echo", "Hi there!")
    print(resp)

def hello():
    resp = zero_client.call("hello_world", None)
    print(resp)


if __name__ == "__main__":
    echo()
    hello()

This is it! Tell me about the learning curve ?

A bit of background

After working on large systems (with 50M+ users) over the years, one of the realization is - we waste a good amount of time writing boilerplate code and clients when working on microservices. And also we mostly use HTTP to communicate among them. This is really fine and usual but http has some overheads (headers, separate tcp connection every request etc). In case of microservice communications we can avoid these to get better performance.
Another thing is usual web frameworks are bulky and has a learning curve. So I was looking for something to reduce these costs and overheads.

Zero is still an idea, though the package is there already ? Zero solves the boilerplate code problem by using RPC like structure, you can just focus on the business logic. And use ZeroMQ rather HTTP to solve the overhead and reconnection problem. Though not both of them are solved explicitly, Zero is still a baby to learn more.

Pros and Cons of Zero over Flask or FastAPI

Pros

  • Inter-service communication is faster as using ZeroMQ and raw TCP under the hood.

  • Simple and easy to learn and use.

  • Extremely lightweight.

  • Super flexible zero can be used only for network communication and you can structure your codebase independently.

Cons

  • Not an HTTP framework, not so much traditional like Flask of FastAPI. People need to understand the actual usage. Like if you have fairly large microservice architecture and there are independent services that communicate among them, zero is a good substitute to reduce network overhead and other framework complexity. But if you only have a few services that communicate directly with the client/frontend, zero is not that much of a use.

  • Only Python based framework. Zero server can only be connected with Python zero client for now. (I have plan to introduce Go, in distant future btw)

  • You always need another HTTP framework as a gateway if your frontend communicates over HTTP, which is the usual and extremely common way.

I will be back!

There are more, I will write more about Zero in coming weeks. For now I will be looking towards comments, opinions and suggestions ?

GitHub: https://github.com/Ananto30/zero


This content originally appeared on DEV Community and was authored by Azizul Haque Ananto


Print Share Comment Cite Upload Translate Updates
APA

Azizul Haque Ananto | Sciencx (2021-09-28T10:18:18+00:00) I have built Zero: Fast and high performance Python RPC framework to build microservices. Retrieved from https://www.scien.cx/2021/09/28/i-have-built-zero-fast-and-high-performance-python-rpc-framework-to-build-microservices/

MLA
" » I have built Zero: Fast and high performance Python RPC framework to build microservices." Azizul Haque Ananto | Sciencx - Tuesday September 28, 2021, https://www.scien.cx/2021/09/28/i-have-built-zero-fast-and-high-performance-python-rpc-framework-to-build-microservices/
HARVARD
Azizul Haque Ananto | Sciencx Tuesday September 28, 2021 » I have built Zero: Fast and high performance Python RPC framework to build microservices., viewed ,<https://www.scien.cx/2021/09/28/i-have-built-zero-fast-and-high-performance-python-rpc-framework-to-build-microservices/>
VANCOUVER
Azizul Haque Ananto | Sciencx - » I have built Zero: Fast and high performance Python RPC framework to build microservices. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/28/i-have-built-zero-fast-and-high-performance-python-rpc-framework-to-build-microservices/
CHICAGO
" » I have built Zero: Fast and high performance Python RPC framework to build microservices." Azizul Haque Ananto | Sciencx - Accessed . https://www.scien.cx/2021/09/28/i-have-built-zero-fast-and-high-performance-python-rpc-framework-to-build-microservices/
IEEE
" » I have built Zero: Fast and high performance Python RPC framework to build microservices." Azizul Haque Ananto | Sciencx [Online]. Available: https://www.scien.cx/2021/09/28/i-have-built-zero-fast-and-high-performance-python-rpc-framework-to-build-microservices/. [Accessed: ]
rf:citation
» I have built Zero: Fast and high performance Python RPC framework to build microservices | Azizul Haque Ananto | Sciencx | https://www.scien.cx/2021/09/28/i-have-built-zero-fast-and-high-performance-python-rpc-framework-to-build-microservices/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.