The task is as follows. A large array of data comes in the JSON format. They need to select several fields and save them to the database. The problem is that there are a lot of such data arrays, the processing of one takes a decent time.
I would like to organize the following system.
http-parser->| Queue |->{Worker_1}->{DB} | Item1 | {Worker_2} | Item2 | {Worker_n} | ItemN | A small Ruby script receives a response from the server, adds it to the queue, and continues and waits for the next response from the server. In turn, the workers, if they see the information in the queue, then they disassemble it and begin to process and save to the database.
At the moment, the difficulty is that the parser is responsible for everything: parsing, sampling, saving to the database, so the processing of responses from the server is very slow.
Zero thought was banal to throw the persistence in the database into a separate thread, but this is not a very flexible solution.
The very first thought was to throw the entire json object straight into the base, and then from there, but then there is the question of how to block the record so that worker_n would not process the same record along with another worker.
In other words, the known methods \ software, which allows to reduce the time of writing to the database, are of interest. In particular, some Amazon Web Services products are of interest. I casually read about Amazon Simple Queue, but I'm not sure that it will cover my tasks.