How to handle 50k+ routes?

hi,

i have many nested routes (nested inside nested inside nested…) and they are full resources so that generates many routes, slowing down my boot time and my application in general

here is my routes file if anyone wants to take a look codedorian.com/config/routes.rb at main · dorianmariecom/codedorian.com · GitHub

is there a way action dispatch could be optimized to handle 50k+ routes (even 100k or 200k or more)?

With that many routes just decompose your app into smaller processes, separate specialized apps

1 Like

Can you talk us through the design philosophy here? I’m struggling to understand why are so many routes needed and how you’re using them.

There are very few occurrences of _path in the code so I guess they’re fetched dynamically but I can’t figure out how.

As for performance, it’s going to be very hard to get good performance out of a router with this approach. You’re trying to use it in a way that’s not intended for it. You’ll get much better performance with a routing tree, like Roda: https://roda.jeremyevans.net/ The routing tree paradigm is much better suitable for very deep routing trees. It’s still just a rack endpoint so you could even mount it inside a Rails router.