I had an interview at flag where I had to design a notification service. I couldn't figure out how to deal with messaging conflicts using a queue.
For example in the messaging queue we have where timestamp_delay2 > timestamp_delay1
notif(user_id, message_content1, timestamp_delay1)
notif(user_id, message_content1, timestamp_delay2)what happens when we add a new notification with timestamp_delay3 so that
timestamp_delay1 < timestamp_delay3 < timestamp_delay2
ie, new message needs to be sent out before time_stamp_delay2 has elapsed.
Do we need to loop through the queue and insert it into the correct position so that when the messages are dequed the timestamps are in chronological order? How do we deal with this efficiently