XaiJu
42Bytes
42Bytes

patreon


Migration to golang: Api v2, WebSockets, Discord

Hello fellow traders!

It has been a while since the last Patreon post, like a few years. 😨

You may already have figured out, I am not a fan of writing articles, yes, my bad.

Psst only between you and me, I’ll share the reason: I am not feeling confident enough in my language skills and articles are big and scary things, better to not mess them up right?

And you can't mess up if there's nothing to mess with, the perfect logic is right there.

Okay, but today is another case.
Today I'll tell you a story about golang. I like to tell ppl about golang.
And about our development plans and what we are doing.

Background

For people who are curious

Currently WFM consists of a few docker services launched across a bunch of servers:

Http + WebSockets + Celery + Manager, all working on python3, all using Flask or its extensions to some extent

The rising problem

WebSockets

Occasionally, especially in recent days, you might have noticed that you could get stuck in a "Connecting..." state and not be able to update your status for 5-20 minutes, and the site would become unresponsive for a short time after that.

The reason behind all of this is that websockets suck and they can’t handle today's load.

After a certain load, they begin to leak memory really hard, sometimes they can derp and slowly exhaust their own ability to accept incoming connections.

It also doesn't help that they are based on a very old and outdated technology that is damn hard to debug and frankly, not even worth trying.

Conclusion: nothing could help them, nothing but a full rewrite on something more modern and more suitable for such a task.

Solution and why it’s golang

Okay, we need to rewrite our WebSockets, but what technology should we choose for such a task?

Initially, I tried to write an extensive comparison between several languages and why I picked golang, but it quickly became 5 pages worth of text and probably needed to write five more on top of that, so I decided to skip this.
But if you would like to see that, let me know.

Here is the short version, as a condensed summary of all my conclusions:

A bit about Golang:

Why not go even further?

This question popped in my head after a decision of rewriting WS was made.

The thing is, we already have a discord bot working on golang, we will have WebSockets on golang…

Logical conclusion would be to rewrite the API in Golang, right?

And the answer is YES.

Usually, it would not be a good solution to rewrite a well established project entirely, as you are going to waste so much resources and time on this.

But i have some counterpoints:

Benefits

What we will get from migration to golang

Blazingly fast execution times

Golang is way faster than python.
We will get x2-x10 performance gain in comparison to the python, even for simple operations that are usually bounded by I\O.

More real time updates

With new websockets we could finally do more real time updates.
Like updating all orders in real time.
Setup trackers and send real time notifications
And everything like that.

Tighter inter-service integration

For example,
You want to get a notification if someone creates an order below a certain price.

  1. Link your discord account to WFM
  2. Some user creates order
  3. we send this info to discord via amqp\\grpc
  4. Discord sends you a PM

Another case is, discord will be able to track your in game status => better status management for some ppl.

Simplified schema on interconnections:

Faster and more reliable development

What is the most interesting, developing in golang gives faster writing time and better code quality thanks to codecoverage and good testing tools and a forced "TEST YOUR F** CODE" policy.
So we are raising TTM and quality.

Looser coupling between parts of the code

Working in a team becomes less problematic, since we are now working on smaller portions of code that is not tightly coupled together and could be developed in parallel and unit-tested independently (still have to do integration test at the end ofc)

You can read about it here, we don't use the same one, but it’s a very similar approach: Hexagonal Architecture

What about new functionality?

I would like to concentrate on the new API and new WS server for now and reimplement what we already have, but at the same time, working on a new backend and especially new api, allows me to adjust many things right away.

So we will have some, in the new API I would like to add:

API v2 and v1

Anticipating your question, APIv1 is now deprecated and will not be updated.

But it will still work, at the very end of v2 development we will notify everyone and there will be 60 days to migrate to the new API.

Websockets

With WS I can’t be so generous, I’ll try to maintain some level of compatibility, but no promises.

All because I have to replace it as soon as possible, due to recent issues.

OAuth2.0

Neat part for all 3rd party devs and users of these applications.
We will have an Oauth server.

What does that mean ?
You will have the ability to register your application within WFM, enabling users to log in without needing their email and password or manually copying a JWT token from cookies.

Each app could have different access rights.

You can read about OAuth here: OAuth2.0
Overall this will allow us to work in a more professional and reliable manner with 3rd party developers and provide more refined access to the api and introduce or alleviate some API limitations like access rights, RPS and everything like that.

More about that later.

Okay, but WHEN ?

Most intriguing question isn’t it?
I would like to say SOON™ …

But, I'll break this tradition today.

New websockets

All core parts are ready, though I will still need to add a few missing actions (such as chat and auctions)

It should take about 1-2 weeks.

I want to replace WS as soon as possible, but I need to be sure that everything is going to work.

New API

Right after websockets deployment.

But it won't be one huge update for the whole v2 API, instead we will deploy v2 and slowly migrate WFM to it, endpoint by endpoint, because development will take some time.

Upcoming articles

Comments

加油

SingSing

hi

Eason-www

How do I unlock my unlimited orders perk? I just subbed

Gunther Hammel

It's not linking to my WF account. Need help.

How can i become a sponsor

I'm really looking forward to it, sounds great for us users and you devs!


More Creators