DEV Community

Cover image for Encore.ts — 9x faster than Express.js & 3x faster than Bun + Zod

Encore.ts — 9x faster than Express.js & 3x faster than Bun + Zod

Marcus Kohlberg on August 02, 2024

A couple of months ago we released Encore.ts — an Open Source backend framework for TypeScript. Since there's already a lot of frameworks out ther...
Collapse
 
nicolabelliardi profile image
NicolaBelliardi

The speed comparisons are compelling, but I’m curious about real-world use cases. Has anyone implemented EncoreTS in a production environment? How did it perform under heavy load, and were there any significant challenges?

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Lots of teams are using Encore in prod, here are some: encore.dev/showcase

Collapse
 
melroy89 profile image
Melroy van den Berg

But then benchmark encore with db calls and some logic. Against for example fastify, with plugins like CORS, helmet, jwt, mysql, swagger and under pressure.

See: github.com/fastify/demo

Thread Thread
 
marcuskohlberg profile image
Marcus Kohlberg

Yeah more benchmarks are coming!

Collapse
 
u007 profile image
James • Edited

also any memory leak issue, i heard bunjs has memory leak. but bunjs has amazing startup time

Collapse
 
starptech profile image
Dustin Deus

Encore is literally a transparent proxy in front of your application. This is a powerful concept. You can compare it with AWS Load Balancer + AWS Lambda or any function runtime. After processing the request, Encore will make an optimized RPC call to your application. Blocking tasks like parsing the request, compression, or validation are done at the proxy level in parallel, which allows your application to do more in the single-threaded environment. A downside that isn't mentioned here is that you have to opt in fully into the framework. You won't be able to work with Node.js HTTP Request/Response objects or Web standards to leverage community plugins and frameworks. You have to wait until Encore provides all these as part of the core, or you have to develop your own modules from scratch.

The benchmarks are the best example of comparing apples and oranges. You shouldn't compare HTTP frameworks while your solution offloads work on a proxy and communicating RPC. The real benefits of Encore are the benefits a transparent proxy/RPC protocol can enable, like automatic tracing, pre/post processing, client generation, and extending your platform with features without building them twice, like CRONs, WebHook, PubSub handling, etc.

In comparison, Fastify is performing quite well here. Run twice as many instances, and you can handle the same load without opting into a full-blown solution. In practice, you still have to deal with a single-threaded JavaScript process. The performance benefits of Encore can become negligible if you don't take care of your application logic. For this purpose, Encore could provide built-in process spawning and load balancing.

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg • Edited

Thanks Dustin! I'll just add that Encore does support exposing the "raw" HTTP request/response. Not sure what plugin/framework you think is unsupported?

Agree it can get a little Apples/Oranges, Encore operates across a bigger share of the stack than most other tools so making a 1:1 comparison is tricky. That's why we included examples of using e.g. Zod for validation as well to show what the performance difference is when the scope is closer to 1:1.

In our benchmarks against Fastify, we've found Encore to be much more performant in various use cases. We're working on the full report to be published soon!

Collapse
 
raibtoffoletto profile image
Raí B. Toffoletto

Encore looks amazing! Specially for putting two of my prefered languages together. But, a question, I get it's performance boost if you have a 8c 16t vps running your backend. But in the age of cloud/k8s is this gain real? I mean now we are running stuff in pods of 1c 1t and we scale up pods when something is overload? I mean... I get the rust is probably better in single core when compared with anything else, but is it bottlenecked but the lack of threads?

Collapse
 
j0nimost profile image
John Nyingi

it's interesting Encore uses multi threading. yet bun is single threaded. Bun offers something called workers as an alternative to multi threading.

Collapse
 
mindplay profile image
Rasmus Schultz

Node supports workers. (Most JS runtimes do.)

Collapse
 
princecee profile image
PrinceCEE

This looks really promising. I'll check it out soon.

Collapse
 
saaduddin profile image
Mohammed Saaduddin Ansari

Can we use encore.ts with sveltekit ? If yes, then how? Is there any example?

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Yeah Encore is frontend agnostic. Don't have any pre-made examples right now though. But give it a go and ask any questions in encore.dev/discord

Collapse
 
juanpabloos profile image
Juan Pablo Olvera Sánchez

Awesome work guys! I'm curious to know if you will also do some benchmark against nest

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Thanks! Yeah we can probably make that happen!

Collapse
 
monjai profile image
mon-jai • Edited

Looks good at first glance, but it seems that some of its core functionality is tied to the proprietary platform offering (such as cloud deployments).

Part of the package installed on our machine appears to be closed source, as I couldn't find the source code for the local dashboard.

Correct me if I am wrong.

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Hey @monjai, there's no runtime dependencies on Encore's platform and everything you need to self-host is open source and documented.

You're right that the local dashboard isn't fully open source yet, this is actively being worked on and will be part of the open source project very soon.

Collapse
 
mistval profile image
Randall • Edited

This obviously took a lot of work and it's pretty cool how you took as much as you could down into native code. I haven't encountered much need for anything faster than Express though personally. Express is already fast enough that real world response time is dominated much more by latency between the user and the server, then latency between the server and external APIs, then latency between the server and databases, than by the performance of application code, and a well-optimized application on any modern framework should be bringing in enough money per instance for the business that the cost of adding more instances is pretty trivial.

Collapse
 
tareksalem profile image
tareksalem

I feel from the documentation that encore was built as a development platform and the purpose of it is totally different from what introduced in this article, I see now you are trying to introduce it as an alternative framework to expresses and other nodejs http libraries but it's bigger than that and also harder than that, is there details how this runs on normal infrastructure rather than cloud, what setup I need and libraries and tools to be installed on the OS to run it on a production server? I think it's more a new environment rather than saying it's a nodejs framework. Great work for sure but I noticed something, u still need to make the platform support more and more tools and libraries that already there, for example regarding event driven, it's not just Gcloud pub sub and aws, there are tons of pub sub tools and queuing tools as well and used on production, how someone for example can use rabbitmq or amq and other tools, what if I am using another db like mongodb, cockroachdb, or other dbs, do u need to build drivers for those tools? If yes, is there a way to use the already existing drivers that already exist so we keep the learning curve simple for new users.

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Thanks Tarek, great comments. Some thoughts:

  • Encore was designed to solve challenges related to building cloud backends, hence the focus of the platform's capabilities is to tackle cloud related hurdles rather than trying to make it simpler to use any type of infrastructure.
  • The framework is independent of the platform, so you can self-host your application if you wish, this is documented here: encore.dev/docs/how-to/self-host
  • You can use any library, queueing infra, or database you wish. There's no magic preventing you from setting up and using that as you normally would for a Node.js application. However, Pub/Sub and Postgres is what Encore has native support for and can automatically orchestrate for you.
Collapse
 
retakenroots profile image
Rene Kootstra

And when you need a dbase call suddenly these performance characteristics do not mean anything anymore, because the dbase trends to become the bottleneck.

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Yeah db calls are definitely a bottleneck, but in our real-world testing the uplift is still very meaningful across the entirety of an applications.

Collapse
 
imamdev_ profile image
Imamuzzaki Abu Salam

https://www.techempower.com/benchmarks/#hw=ph&test=composite&section=data-r22

I hope you're enlisted here soon, dear Encore.ts.

Collapse
 
mrbns profile image
Mr. Binary Sniper

I am Deno fanboy. Just wondering is there any way to use it with Deno ?

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Coming soon!

Collapse
 
kravetsone profile image
Kravets

Why u compare it with one of the slowest validators?

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

We picked it because it's one of the most commonly used so the information would be most relevant to people.

Collapse
 
timsar2 profile image
timsar2

How to config angular ssr to use Encore instead of express?

Collapse
 
speedopasanen profile image
Toni

Have you considered making a Typescript SDK creator? Think TRPC style, ditching the whole Rest paradigm.

Collapse
 
kravetsone profile image
Kravets

Elysiajs?

Collapse
 
sub8s profile image
Subrahmanya S M

https2 and QUICK protocol support available?

Collapse
 
dfedotov profile image
Dmitry Fedotov • Edited

"Interface"s are not safe and are usually avoided, I would use TypeScript "Type"s, would it work with "Type"s as well?

Collapse
 
nabwinsaud profile image
Nabin

It feels like the cocktail of cloud + framework I don't get any better use cases like nestjs but seems cool in case of performance

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

I think compared to nestjs you get a bunch of benefits when it comes to building distributed applications, like type-safety when using queues etc.

Collapse
 
waldemar_reusch_f6ab9868e profile image
Waldemar Reusch

It would be fairer to compare with typia instead of zod, since JSON parsing and validation is a known bottleneck

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

Interesting. The rationale for including zod in the benchmark is that it's very established and commonly used for validation, which Encore does out of the box.

Collapse
 
ibolmo profile image
Olmo Maldonado • Edited

Looks really great I'll give it a try. Since the encore runtime is very decoupled are there any plans on supporting a python sdk?

Collapse
 
marcuskohlberg profile image
Marcus Kohlberg

It's the next language we're planning on adding support for, our ambition is in the next 6 months.