I have got a functionality on my client side that will create 40 apartment objects in DB with an array of objects with credentials in it. I was wondering what would be the best approach to create 40 objects in DB sent from the client side. Is it better to pass the array of objects as a parameter to the POST HTTP request and send a 1 POST request? OR Is it better iterate the array of objects to send 40 POST requests one by one to the server? (Side note: The server is built with Ruby on Rails with Postgres)
If your application has a heavy network usage, consider the former, sending one single POST request and processing on Rails end. On the other hand, if you're scarce on computing resources (say you're not using any concurrent webserver such as Puma) consider the first approach, as more clients can be served.
On my production application I tend to go for 1 single POST as we can handle multiple users, so if one CPU is busy accessing the database, subsequent API calls can still be served as there's still enough pool.
Plus with 1 single POST you could wrap everything in a single atomic operation and rollback if s**t hits the fan.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With