We have a table in Redshift:
people
people_id people_tele people_email role
1 8989898332 john@gmail.com manager
2 8989898333 steve@gmail.com manager
3 8989898334 andrew@gmail.com manager
4 8989898335 george@gmail.com manager
I have a few users who would query the table like:
select * from people where role = 'manager' limit 1;
The system users are basically phone calling these people for up-selling products. So, when the query return results, it should not return same people ever.
For ex.
If User A executes the query - select * from people where role = 'manager' limit 1;
, then he should get the result:
people_id people_tele people_email role
1 8989898332 john@gmail.com manager
If User B executes the query - select * from people where role = 'manager' limit 1;
, then he should get the result:
people_id people_tele people_email role
2 8989898333 steve@gmail.com manager
APPROACH 1
So, I thought of adding a is_processed
column to not return the same results. So, after User A executes the query, the table would look something like:
people_id people_tele people_email role is_processed
1 8989898332 john@gmail.com manager 1
2 8989898333 steve@gmail.com manager 0
3 8989898334 andrew@gmail.com manager 0
4 8989898335 george@gmail.com manager 0
APPROACH 2
Another thought was to create another table called - query_history
where I have:
query_id people_id processed_time
1 1 22 Jan 2020, 4pm
2 2 22 Jan 2020, 5pm
QUESTION
My question is what happens when User A and User B queries at the EXACT same time? The system would return the same people_id at that moment and 2 phone calls would be made to the same person.
How can I solve the concurrency problem?