Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you have multiple aj per app with Arcjet? #2159

Open
lancejpollard opened this issue Nov 5, 2024 · 2 comments
Open

Can you have multiple aj per app with Arcjet? #2159

lancejpollard opened this issue Nov 5, 2024 · 2 comments

Comments

@lancejpollard
Copy link

lancejpollard commented Nov 5, 2024

How does it know how to store permanently the rate limiting stuff? Can I have multiple const aj = arcjet({...}) per project, like in theory one per route.ts?

That way, I can say "for this route, rate limit like this, for that route, rate limit this other way", etc..

Will that just work?

All of the sample apps only have 1 aj per app, so I'm not sure.

@davidmytton
Copy link
Contributor

Hi @lancejpollard ! Yes, you can have. multiple aj instances per app. We set it up like this so that we can have base rules that apply everywhere we use that instance, but then use withRule to apply per route rules. You don't have to use the same aj instance, but we do it because then we only need to instantiate the client once.

This has some performance benefits because we instantiate the bundled WebAssembly module when the client is created. There is also no shared local cache across instances so if a user gets blocked from one rule from one instance, there wouldn't be anything in the cache in another instance.

Does that help?

@Muhammad-Owais-Warsi
Copy link

Hey @davidmytton, as in the pricing of Arcjet, it is mentioned that in the free plan we can use upto 5 rules, so if we create multiple instances , we can have 5 rules in each instance or just 5 rules in total ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants