0

I've been interviewed by some experienced engineer, when he strongly disagreed with some statements I said:

  • Assuming full control over your applications, It's a standard practice to make writes-to-database exclusive to one single application or controller (not about multiple application instances, but different applications).

  • Assuming full control over design, synchronization is better implemented using observer pattern than using polling from both ends.

I'd really like for some experienced engineers to enlighten me on those 2 main points, and point to me if I've been right/wrong about them.

  • 3
    No, I've never seen anyone make your first assertion. – Robert Harvey Jun 15 at 1:07
  • 1
    I'm not sure what you mean by "using polling from both ends." In general, the decision whether to poll or use events is an "it depends" decision. – Robert Harvey Jun 15 at 1:08
  • 1
    if I want to detect changes to the database, wouldn't it be simpler and cleaner to allow the writes only through a single channel -- Yes, if that is your goal. Most of the time, it shouldn't be necessary. – Robert Harvey Jun 15 at 1:52
  • 1
    I don't know what "polling with versioning" means. – Robert Harvey Jun 15 at 1:52
  • 3
    One of the biggest shifts in design with a DB is which is considered the single source of truth: application state or the DB. If the DB is truth then multiple writers aren't a problem. If application state is truth then multiple writers are a problem. – candied_orange Jun 15 at 6:23
2

Is it a standard practice to have only one application writing in the database?

Not at all. A database is in general used to store, share and integrate information between many applications.

This is not to be confused with the very special situation of microservices, where often a database may be used exclusively by one service.

Is it a standard practice to make writes exclusive to a single controller

Not either. However, controllers have different roles in different architectural models, so it may depend. But if an application has different controllers (e.g. ECB model) , it's not rare either that each controller writes databases for its area of responsibility.

Note that in some systems the database accesses are isolated in a component or in a layer in charge of the persistence. But these components are rarely called 'controller".

Is synchronisation better implemented using the observer pattern ?

Define "better"! For some, better is more performant. For other it's more independence. For other it's the richness of information.

But nevertheless, yes, the observer pattern can have some advantages over polling in terms of performance:

  • polling from both ends, mean that two systems constantly query the data from the other system to find out needs to synchronize. This can be costly, especially if one there can be longer iddle-times on one of the system, thus causing unnecessary queries. Polling also requires one system to know the data structures from the other system.
  • observer pattern means that the writing system application informs its subscribers that something had happened. So data is queried only when it changes.

There are now a lot of systems that are build on an event oriented architecture. The events serve as a backbone and work according to the principle of the observer (the event queue is observed). This model can achieve high throughput in highly distributed systems.

Remark: the observer has nothing to do with versioning. The kind of "versioning" you are speaking in your comments is called event sourcing: this is a very special design for basing not only the synchronisation on events but also the persistence of objects. In this design you no longer save the state of an object, but the susccession of events that affect the state. This is realated to events, not really to the observer.

| improve this answer | |
  • 1
    Thanks for your answer, it was really helpful. The problem might have been that I used general statements while I've been talking about more specific (dominant maybe) use case. I can easily infer want I'd been trying to say from your answer, although it might give the opposite impression at first glance. – Samha' Jun 15 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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