1. 11
    Go vs. Rust for back-end development ask go rust

Hello,

I’m planning to work on a trading platform and looking for high-performance web framework and Websocket server.

Trading platform will require authentication, so support for middleware is important. Basically, I’m looking for high-performance web framework with middleware support.

I also wonder why you choose that framework for that purpose? And what is the advantage of the programming language that web framework is built on compared to the other.

(I’m planning to store the historical trading data on InfluxDB or Redis time series, also it could be great if you may provide insight about them.)

  1.  

  2. 13

    What resources have you found in your research so far? Why have you limited to these two choices? What your goals for your project? What differences are you weighing that you’d like people’s thoughts on? This doesn’t sound like a serious question.

    1. 3

      I have found two interesting web frameworks that is high performance:

      • Actix (Rust)
      • Echo (Go)

      Actually one of the reasons that I limited these to two choices is I love working with these two languages and both are interesting languages, but also after research AFAIK there is no high-performance Python (I love working with Python too) framework that might be suitable for this.

      My goals for this project is build a high-performance trading platform that is scalable and high-performance, it is actually not a serious project right now but I want to explore this area, that’s one of the reasons why I am asking about the right framework & websocket server.

      Sorry for not providing more information on the question, I hope it is helpful. Please let me know if there is still something that I can add.

      1. 11

        The framework pattern isn’t as much of a “thing” in Go as it is in many (most?) other languages. (The language deliberately doesn’t provide the expressive power and affordances that frameworks tend to need.) Consequently, frameworks in Go are less necessary, and less useful, versus many other languages. They each might have their slightly different architectures and might be better or worse on various metrics, but in the end they all boil down to sugar over net/http.

        I write all this to say: consider the language independent of any particular web package or framework or whatever. Also, quantify “high performance” before you start making decisions based on it :) And stay away from fasthttp.

        1. 2

          And stay away from fasthttp

          Other than lack of HTTP/2 support, what reason is there for avoiding fasthttp?

          1. 6

            Another big reason is it doesn’t do HTTP/1, either: many corner cases and details are simply not implemented. Also, it doesn’t reuse any of the net/http interfaces, so using it sequesters you in a totally separate ecosystem. But really, the code is just a mess. The structure is emergent, clearly not designed — the documentation is written without care or consistency — it feels like somebody’s hackathon project.

        2. 4

          Are you talking about high-frequency trading here, or is this just a general “I’m making a web app” question? There are plenty of easy-search-able results that include benchmarks for popular web frameworks.

          I’m also interested in how you came to the conclusion that “there is no high-performance Python.”

          1. 2

            I believe it actually involves high frequency trading, that is why I felt required to ask. I know Actix is one of the fastest web frameworks, but is Rust true language for high-frequency trading and does it makes sense to use Rust. Also same for Go, Go have very fast web frameworks. That is why I compare these two languages.

            Python being higher-level language with lots of abstractions was one of the reasons made me think that it is not high-performance, also I have never seen real life usage of Python in HFT area but if Python is actually suitable, I’d like to learn more.

            1. 7

              The application serving web requests is (hopefully?) not the same one executing HFT strategies. Any reasonable modern language will be fine for the former.

              1. 5

                Most of the already existing high-frequency trading apps are written in C++, however popularity is not a particularly good benchmark when it comes to building something new. I’d say give both a try and benchmark your algorithms’ implementations on both platforms. The results might be surprising; it’s very easy to write something that’s fast on Go and slow on Rust, and vice-versa, due to the different programming styles on both languages.

                1. 5

                  Do you think you can realistically compete with the FPGA and CUDA-based implementations at the big firms?

                  1. 1

                    What do they use CUDA for?

                    1. 1

                      This paper has some background: http://ceur-ws.org/Vol-2147/p09.pdf

              2. 3

                According to these benchmarks Echo (Go) is not high performance compared to Actix (Rust) - the difference is embarrassing: https://www.techempower.com/benchmarks/

            2. 11

              Do you know either language?

              Use the one that you know.

              If you love working with Python, then I’d suggest Go. Rust would likely be too much cognitive overhead for little benefit.

              1. 5

                Interesting. I would have the exact opposite reaction. Go will make you think about raw pointers and that kind of thing, whereas rust you can write at a high-level like Python.

                Totally agree use the one you know unless you have a desire to learn a new one.

                1. 18

                  If pointers are too much cognitive load then Rust’s lifetimes and ownership juggling is going to be way worse. I’d say that the comparison is more that Python and Go are not particularly functional languages, while Rust obviously is (and that’s the appeal of it to people who like functional languages).

                  If Rust is faster for a given use case that’s a more like-for-like basis for comparison, but then you might want to use Fortran to go even faster depending on the use case. ;-)

                  1. 4

                    Admittedly I’ve invested time in becoming comfortable with Rust, but I actually concur – after gaining some familiarity, Rust feels much higher level than Go.

                    1. 6

                      Rust does can definitely operate at a higher level than Go, but it also has a lot more cognitive overhead.

                  2. 5

                    Pointers in Go are pretty trivial to work with, and I say this coming to Go from Ruby. Basically your only concern with points are “they can be nil,” otherwise you barely need to differentiate between pointer and structs if you’re writing idiomatically (that is a gross oversimplification and there are performance implications at times, but it’s extremely unlike C/C++ in this respect).

                2. 7

                  I have written a few microservices in both Go and Rust (including translating some from Go to Rust). There are benefits, particularly over Python (my previous go-to language), but you must recognize that you’re trading a decent amount of maturity for a number of rough edges. In the cases where I am using Rust, that’s fine – but I am also consciously using it for small, self-contained components until the web and database stories “firm up” some. If you’re curious, the frameworks I use are tokio and warp. warp is a higher-level abstraction on top of hyper. For database work I have had some success with sqlx.

                  1. 6

                    Reading the comments, it seems like you are building something for high-frequency trading. That’s great and all, and I really appreciate it, but a heads up, it will be very hard to compete with big players running on hardware with just meters of fiber-cable to the exchanges. Only the very fastest can come out in the black in that game, and that normally means paying to be physically at the exchanges and paying to have superior hardware. But, if you are not in it to “beat the market”, but for research purposes, or curiosity, cred to you.

                    If you are in it to actually get one up on the markets, then I would figure out some other edge than being faster. There are plenty of options and opportunities for winning strategies for those that have the time, perseverance and grit, that it takes to do something like that. If you go down that road, the choice of tech-stack is irrelevant as long as it does what you want it to do.

                    If you don’t already know Rust, then I’d go with Go. You will be up and running with something much quicker.

                    Good luck

                    1. 11

                      As a language Rust is significantly better than Go, for any purpose.

                      But a much better selection of libraries will be available to you if you use Go, and you’ll just have better community support in general.

                      1. 15

                        As a language Rust is significantly better than Go, for any purpose.

                        Depends on the metric — how about time to productivity? ;)

                        1. 3

                          I picked up Go as a Python programmer, and it indeed was easy to get up to speed with, and start enjoying it for the added (compared to Python) benefits of static typing and concurrency.

                          Of course, learning never stops if you keep yourself curious, so I wasn’t going to keep proclaiming that Go is the best. I happened to use and immensely enjoy Elm later, which – due to its shortcomings – lead to learning Haskell (now that had quite a learning curve). With that knowledge now in my belt, I’d certainly choose Rust over Go if presented a choice. In the end, I am far more productive in Haskell than Go or Python. I’m pretty sure Rust would fall in that spectrum.

                          Now, in a team setting you are going to compromise and deal with what’s best for the team. Unless you change teams / companies, like I did when wanting to write Haskell by default. So, there are quite a range of factors – technical, social and personal – when it comes to someone choosing a programming language for use in a project.

                          1. 1

                            Maybe you’re an exception but that approximately no one is more productive in haskell than go seems easy to conclude from looking at what’s produced by each community.

                            1. 1

                              Just a note, but solo productivity by language probably doesn’t translate to group productivity by language in most cases.

                            2. 2

                              Depends on the meta-metric. There are definitely cases where focusing on the minimization of a fixed cost like time to productivity is strategically sound, but I don’t think those cases are anywhere near as common as one might guess from how often that metric is lauded.

                              1. 1

                                Fixed cost per developer on the project, sure, but healthy projects necessarily have a constantly rotating pool of developers, don’t they?

                            1. 3

                              I think you should choose Go (golang) unless there is something specific you want that Rust offers. This is the correct response.

                              1. 3

                                for HFT trading you most likely will need:

                                So with the above said, and if you have to choose between Go or Rust, choose the one that offers the closest match to the tools/libraries you will for the above list.

                                Website, is really just a UI on top of an API that will be reading state changes, providing control commands to the machinery implemented with the above tools. I would, personally, not base a choice of a programming language for HFT, on the web backend. Web backend for UI is one of the least relevant pieces, in my view.

                                1. 3

                                  Use what you are the most familiar and feel productive with, then work on it to be horizontally scalable.

                                  1. 3

                                    You seem to be focused on web framework performance, but mention other components (auth middleware, historical data store) that are also going to impact speed of page delivery. It won’t matter how fast your web framework is if each request hists the datastore, for example – the datastore is likely going to be your bottleneck.

                                    It’s also unclear whether this app is intended to include the machine learning logic to make trades (in which case you probably don’t want a web app), just offer reporting and analysis (in which case, pretty much any language will do because you’ll spend all the time in your database/warehouse/whatnot), or something else entirely.

                                    Can you be more clear about the requirements you need to fill?

                                    1. 3

                                      Why not ada or nim?

                                      1. 2

                                        Or Pony