Using Rust to write scalable Python APIs

Поділитися
Вставка
  • Опубліковано 27 гру 2024

КОМЕНТАРІ •

  • @dinoscheidt
    @dinoscheidt 9 місяців тому +16

    0:16 when you are in a high throughput api situation the first thing people usually do is add an API load balancer, or an extra 10 bucks to the machine. I agree that rust has very interesting properties and should be i.e. a first choice for embedded & runtime development. But flipping the whole api stack from FastAPI to Rust to get a 2-4x requests per instance (fastapi is pretty fast) wont help you in real high throughput situations… at least before worrying about read and writes to your DB. At scale compute and bandwidth is cheap… unlike your time.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  9 місяців тому +9

      This is a very good point! However, if you're doing really CPU-intensive work, scaling horizontally can become fairly inefficient. Hiring 100s of machines with 0.5 vCPUs will eventually outstrip the cost of having an engineer or two write the performance critical parts of the applications in Rust.
      Further, while FastAPI is really fast, thanks to (current) Python, it's inherently single-threaded. Robyn makes it easier to use multiple threads thanks to Rust crates like Rayon.
      Definitely agree with your point if you've already got a large application :)

    • @xijinping5064
      @xijinping5064 9 місяців тому +3

      That's only true for services that are just doing network calls to other services like databases and stuff. For any compute intensive stuff where you want to take advantage of better hardware or more cores, you'll definitely see why Rust is so good. (or maybe a simpler lang like Go).

    • @savire.ergheiz
      @savire.ergheiz 8 місяців тому

      ​@@IsaacHarrisHoltFastAPI were intended to covers general use cases.
      Once you got specific needs then you can of course use optimized version of what you need and yeah it does not need to be in python.
      The benefit of learning new framework are minuscule by then.
      If its cpu core performance then there are plenty of it besides rust that are already exist there within C libs usually.
      Rust is good but its still lack a lot of production ready libs that peoples usually needs.
      Clients don't care what we used. They cared for time to deliver and costs.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому

      Robyn does also cover general use cases, but it gives you some flexibility. Of course there are other ways to achieve the same. This is just one way of doing things

    • @savire.ergheiz
      @savire.ergheiz 8 місяців тому

      @@IsaacHarrisHolt I just don't see any benefit learning new stuff just to follow trends.
      There is no such thing as perfect stack. Experiences from using it matter by a lot.

  • @keenoogodlike
    @keenoogodlike 9 місяців тому +21

    Rust really adopt everywhere now, glad I have more Python web framework to use.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  9 місяців тому +3

      Yes, it's great! More Rust-Python to come 😉

  • @GoldenBeholden
    @GoldenBeholden 9 місяців тому +9

    I'll give this one a shot. My experience with FastAPI has been plagued by weird hangups.

  • @Mustafa-099
    @Mustafa-099 8 місяців тому +3

    The addition of memes is a nice touch, keep it up Issac!!!

  • @Darkev77
    @Darkev77 9 місяців тому +7

    I’m seeing a lot of libraries adopting Rust as the main building block recently, and for a good reason I suppose. Though Isaac, what’s your take on Zig as compared to Rust, we’ve got Bun and TigerBeetle build using Zig

    • @mikkelens
      @mikkelens 9 місяців тому

      The thing with rewriting a performance critical python system in another language is that you already know that this thing is going to be used for a while, and you also know you need it to work without any flaws, and you are probably willing to put a bit of extra work into it. Zig doesn't offer the safety or correctness (type system) that rust offers, and if you're already rewriting it from python under these circumstances, the zig argument of "easier to write than rust for c/c++ programmers" isn't really that relevant. Certain projects that rely on a lot of stuff that zig's `comptime` system is excellent for and for whatever reason doesn't need the guardrails rust puts for you (e.g. you're writing it for yourself only) certainly might enjoy zig to a greater extent than rust, but thats a way smaller niche than the giant pool of potential rust applications in the current world of software. Rust isn't the be-all-end-all, but it makes it hard to argue for other languages that do not go beyond it in most of the areas people care about.

    • @Darkev77
      @Darkev77 9 місяців тому

      @@mikkelens very interesting take, thanks a lot! But don’t you think Zig overcomes much of the safety concerns (bound checks, deferring allocations, etc.) without sacrificing flexibility? It’s more concise I’d say than Rust and less bloated since Rust is filled with macros and standard feature updates that keep growing, which adds a lot of complexity. Also, for systems where you require fine grain control over the memory, such as in embedded systems, I see that eventually Zig would overcome C in this domain since Rust don’t offer you much in this unsafe environment

    • @steveoc64
      @steveoc64 9 місяців тому +4

      Very philosophical argument there.
      Some may believe that safety and correctness come from good design, and the ability to control how the system operates as you build it. The responsibility here rests on the programmers.
      Some may believe that safety and correctness are better achieved by using tools that remove control and restrict design. The responsibility here rests with the tooling, and whatever decisions were made by the central planning committee who provides those tools.
      This discussion has been active for the last 40 years in programming.. and much longer than that in general engineering.
      The 2 points of view are never going to agree with each other.
      The proponents of the restrictive approach will point out cases where programmers have shipped software with bugs .. therefore cannot be trusted to write code.
      The proponents of personal responsibility will point out cases where entire countries have collapsed due to the inherent problems with central planning and control.
      It is not surprising that people’s choices in these areas of programming tools strangely correlate to their political views, and positions on many contemporary controversies.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  9 місяців тому +4

      These are all very interesting points. Personally, I think Zig and Rust can both be used reasonably interchangeably - they both achieve the same thing, but have different philosophies and ways of going about it.
      Zig will definitely give you more control, and you'll likely be able to achieve higher speeds using it as a result. However, Rust's performance is also incredible, and it's relatively easy to write performance Rust code. Probably easier than Zig.
      That said, it's fairly easy to write crap code in both languages.
      To be honest, I can't offer much more of an opinion here - I haven't used Zig much outside of the Impatient Devs video I did. I've used Rust more, though not extensively, and not for any large projects.

    • @Darkev77
      @Darkev77 9 місяців тому +1

      @@steveoc64 totally agree, and interesting note on the political side lol

  • @TobiasDSI
    @TobiasDSI 5 місяців тому +2

    Need a uv-Video ;)

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  5 місяців тому

      Sadly I don't do much in the way of Python content any more - it's pretty much all Gleam now!

  • @karthikb.s.k.4486
    @karthikb.s.k.4486 9 місяців тому

    Great video. What is the IDE and terminal settings you have used could you please provide steps to setup.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому

      I use AstroNvim with ZSH terminal, OMZ and P10k

  • @pietraderdetective8953
    @pietraderdetective8953 9 місяців тому +3

    Granian is another interesting Rust-based Python library..it's a server runner.
    It increased my RPS by 7x !!

  • @filipbartos7584
    @filipbartos7584 8 місяців тому +2

    It´s great that new framworks arise, but programmers keep in mind that, new and faster doesnt mean better. Robyn is rather young and probably not as used as fastapi meaning that fastapi is more mature and thus more suitable for your needs. And if you hear in your head "but it is faster so my app will be faster" well it wont. Most of web apps are slow not because of framework they use, but because of their code, their app design, their queries to database. If you want to see 3x 10x 100x speedup improvements, start with your code, your implementation, your queries to database, rather than looking for an error somewhere else. With all that said if you are keen on experimenting and you have new project go ahead and try Robyn or any other framework practice makes perfect, but keep in mind that all that glitters is not gold.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому +1

      I 100% agree with this take! I mostly wanted to show off the library a bit because I think it's a really cool project maintained by some really great people.
      And yes, you're right about async stuff. Robyn won't reduce request times much if at all, but it may be able to improve throughput by providing a better underlying server and so on.
      Also, the simple Rust integration is great for CPU-bound tasks.

  • @towu
    @towu 9 місяців тому +1

    Thanks for covering this! Do you have a discord server?

  • @po6577
    @po6577 9 місяців тому +5

    we need uv video!!!

  • @Alexciaooo
    @Alexciaooo 9 місяців тому +2

    Please, make the video on uv. I'm really interested :)

  • @faysoufox
    @faysoufox 8 місяців тому +1

    Thank you, and your channel looks interesting, I've just subscribed to it

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому

      Thanks! I hope you found the video useful

  • @v4ldevrr4m47
    @v4ldevrr4m47 8 місяців тому +1

    Nowdays all thtr implement Rust is looking some sexy :D .... Knowing Rbyn this 2024 when checking alternatives to sanic. Thanks 4 this video.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому

      You're welcome! I hope you find it useful

  • @nirmalsankalana7970
    @nirmalsankalana7970 7 місяців тому

    This is sick

  • @SR-zi1pw
    @SR-zi1pw 9 місяців тому

    Nice content why Batman running 😂😂

  • @RamVelagala
    @RamVelagala 8 місяців тому +2

    Just started fast api😂 too late i guess

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому +1

      FastAPI is still great! I use it in production at the moment

  • @dopesubbox7277
    @dopesubbox7277 8 місяців тому

    This is quality content, I can’t help but feel that all the gifs and other hallmarks of garbage programming content cheapen your work a bit
    I don’t think you should want to emulate fireship when you actually have something useful to say

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому

      Appreciate the feedback! I'd love to be able to do more useful animations etc., but it's difficult to find the time at the moment :)

  • @Flameandfireclan
    @Flameandfireclan 8 місяців тому

    Is it cool, yeah.
    Will i use it, most likely not

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому

      That's fair! There's a cost to switching

    • @Flameandfireclan
      @Flameandfireclan 8 місяців тому

      @@IsaacHarrisHolt Yeah, exactly. That is one thing I think many of the developers who develop and try and “sell” developers a new framework, OSS library, toolkit etc forget. Is that what you have built isn’t “unique” or solves a problem for us that we couldn’t solve before.
      IMO I think that is why business oriented developers make for such great innovators.
      Look at React, nextJs or FastAPI. They got created when people needed it the most.
      I think for the next generation of developers that want to create Open source tech that gets mass adoption is to really look into what the problems current developers are facing and come up with a solution that is better than current implementations.
      I think for Robyn to rival FastAPI it needs to literally have everything that FastAPI offers (web sockets, JWT a really fast WSGI/ASGI). Speed I think is what could give Robyn it’s edge.
      I love FastAPI (Used to develop a lot of projects in flask. But as soon as I learned about FastAPI I left flask for good whenever I wanted a heavyweight backend or a heavyweight API). And also the fact that I can switch between WSGI is not a bad thing. It’s a good think and means I not locked in.
      I hate libraries that literally shove down shit my throat and force me to use things I don’t need or want to use.
      A love a flexible, adaptable and straightforward library.

  •  6 місяців тому

    I use Rust instead of Python.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  6 місяців тому

      Totally fair! You don't have to use Python. I like it because it's really easy to be productive and has a great ecosystem

    •  6 місяців тому

      @@IsaacHarrisHolt With Rust it's even easier according to my experience. Type checking is superior, error handling is superior, metaprogramming is superior, abstraction is superior. And it offers top speed always.

    • @vurmyr
      @vurmyr 6 місяців тому

      True. But this type of interoperability comes handy when you need to integrate existing Python code and libraries, especially from other teams that only write Python.

    •  6 місяців тому

      @@vurmyr Of course.

  • @tartakOO
    @tartakOO 8 місяців тому

    Good content, terrible and exhausting montage. Please take a breath.

  • @motbus3
    @motbus3 9 місяців тому

    This is all relative. If you were doing APIs in Python without a major reason it was already a problem.
    I love python. I am a python engineer and it sucks at performance.if you have something simple, why dont do it in java or .net. they are terrible languages but they work. If rust has a great backend API, it is even better.
    Ps. If you do backend in js, please, stop if you dont have good reasons.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  9 місяців тому +1

      The main benefits of doing things in Python are ecosystem and developer velocity. Also, you might only have a single CPU-intensive route amongst 100 other routes. Not a lot of point rewriting your entire app in a more difficult language for that

    • @minciNashu
      @minciNashu 9 місяців тому +1

      It depends what team you got.
      pypy3 with granian and async Python can pump some good RPS. So do JS backends on Bun.
      Why hire new people or learn different languages if your team is comfortable with Python or JS?

    • @pietraderdetective8953
      @pietraderdetective8953 9 місяців тому

      ​@@minciNashu tried Granian, it 7x my RPS (using Quart as web framework).
      Unfortunately it doesn't work with Vercel..so my usage is limited to the local server.

    • @ImHencke
      @ImHencke 8 місяців тому

      .NET/C# is great for backends, simple ones too

  • @Ca1vema
    @Ca1vema 8 місяців тому

    Remember when python developers invented wsgi so no python app is bound to a particular web server or framework? Yes, gen z ruining all once again with their "innovation"

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому

      This is a very... close-minded take. There are plenty of ways to do things, and the industry as a whole is trending back towards simpler things. Why can't that be the case here too?

    • @Ca1vema
      @Ca1vema 8 місяців тому

      @IsaacHarrisHolt because frameworks come and go.
      Also, Robyn is not a simpler thing.

  • @myway6335
    @myway6335 8 місяців тому

    Fastapi is not comparable with rust frameworks. Everything you do in Fastapi takes 10 times less than in any rust framework.

    • @IsaacHarrisHolt
      @IsaacHarrisHolt  8 місяців тому +1

      Because it's written in Python. Like a Robyn app :)