I need to design a REST API for importing an employee CSV file with 30 columns. Number of records in the file may vary based on the size of business,could be 10, could be 5000.
Here's my approach to design
In case of the first two options, the user is expected to read CSV and convert to JSON before sending.
Questions
Because I am not familiar with javascript, so my answer will focus on question 1, about how to design an api for importing large amounts of data. There are generally two ways, synchronous and asynchronous.
In order to avoid a long wait for importing data into the database, we should limit the number of data rows per request. If the data imported by user exceeds the limitation, the frontend needs to split the data into multiple requests. For a better user experience, we can display the current import progress.
Compared to synchronous way, it's a little more complicated to implement asynchronous.
1.We can upload csv or json file to Amazon S3, then send file address to the server via api.
2.The asynchronous worker start importing data into the database after downing file from s3. In order to avoid database blocking, we also have to import in batches.
3.In order to get import progress, the frontend polls via api or server notify the frontend after the import is complete.
Both ways have pros and cons, which way you choose depends on the trad-off between the amount of data and the complexity of the implementation.
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