Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This is more a learning question than coding, but I'm certain it's a common issue for anyone developing administration systems or applications in php/mysql/js etc.

I've developed quite a complex application that lets users upload images, and define hotspots in them with associated actions. The images are stored in a table, and the actions in another, with json data for every action in a text field. However, like I say, the problem is generic.

Basically, my fear is that if someone is editing the same image and set of actions at the same time, and they both submit changes, or if it was edited by someone else then there's a whole series of structures that potentially will fail on submission.

I don't want to implement a locking system, as the system is very wide ranging (links to other images, etc), and I think it's a bit ugly. I saw this link (MSDN Multi-tenant architecture article) in another question, but it seems a little overwhelming and specialised for sql server.

So - what are the terms for data and system architecture here that I can investigate, or are there some good articles to do with this topic that people can recommend? Specifically for php/web world would be great!

share|improve this question
3  
The generic term you are looking for is concurrency. Not an answer, obviously, but may help your research... –  Yannis Rizos Jan 14 '12 at 13:19
    
I think you need to decide what you want to happen and then find solutions to make it work. Example: the second/conflicting changes just get ignored (users won't like it, but it's doable.). –  JeffO Jan 14 '12 at 16:05
    
@JeffO Actually I think the question is more on relevant terms, concepts & resources than on an actual solution. –  Yannis Rizos Jan 14 '12 at 16:32
add comment

1 Answer

up vote 2 down vote accepted

In a lot of situations, the simple technique of "last writer wins" can be sufficient.

Last writer wins means that the last person to save has his changes kept; any changes made while that person was editing are lost.

While this might seem a crazy approach, consider that in many systems the source of change is to synchronise with the real world.

Consider a system listing customers with their addresses and phone numbers. Imagine that one of their customers, Mary, has recently moved house. She sent in a change of address card to your compand. Her husband, John, didn't know about this and has phoned in to update details through the customer centre. Coincidentally, the change of address card is being processed concurrently with the phone call.

Which change should be kept? It doesn't matter - because both edits will be changing the house address to the same value.

You also need to keep in mind the potential frequency of concurrent updates - it's actually pretty unlikely that the phone call and processing of the change of address card would happen at the same time. If the card was processed first, John would find the details already correct when he called; if the card was processed last, the operator would find the details already correct. In either case, no conflict.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.