3

We are developing a Rails app that will include an API for our customers. Let's say that with this API, they can create Puppies. Many services that provide an API, include a 'sandbox' mode, in which they can, for example, create bogus resources to make sure their integration is correct. We'd like to include a 'sandbox' mode to our API.

I am aware that a simple solution for adding a sandbox mode to an API is to create a 'sandbox' environment (similar to production, but without some business logic that should happen only on real production transactions) and ask our customers to call the sandbox environment when making sandbox API calls. However, since Rails 6 now includes support for multiple databases, we are also considering adding a secondary database to the Puppy model to handle sandbox calls (i.e. write and read records that were made on the 'sandbox' mode). We figure we could in theory make this work by creating a custom DatabaseSelector::Resolver that checks the session and decides if it uses the 'sandbox' database or the main one, depending for example if the credentials passed to the API call are 'sandbox' or 'production' credentials.

Do you think this approach is feasible? What would the pros and cons of this approach be vs others? (e.g. sandbox environment, adding a Puppy#is_sandbox column and scoping records, etc.)

6
  • "However, since Rails 6 now includes support for multiple databases, we are also considering adding a secondary database to the Puppy model to handle sandbox calls (i.e. write and read records that were made on the 'sandbox' mode)" I'm curious about that. Wouldn't that be a bottleneck? As in, handle the load for all your sandbox request and production at rails layer. I mean I don't have an answer I'm just seeing possible issues. In my head, I would rather have two different instance and handle sandbox at DNS layer. Commented Sep 16, 2019 at 17:30
  • 1
    @thelastinuit you are right, there definitely would be increased processing on the same production environment if we went with this solution. However, I don't think there will be many sandbox calls to our API (only at the beginning, when our customers make their integration). Also, the possible bottleneck wouldn't happen at the database layer (since databases are separate), but at the 'routing' level, which I think is easy to scale. Maybe I'm being biased already towards this solution, so I will validate this. Thanks for bringing this up! Commented Sep 16, 2019 at 17:57
  • No idea, to be honest. I'm just throwing thoughts, maybe you can see more on this. Commented Sep 17, 2019 at 16:08
  • @DanielOlivares Did you ever get any solution for this? Commented May 8, 2021 at 10:58
  • @DanielOlivares did you find any solution on this? Commented Jan 20, 2022 at 10:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.