60

Plenty of sensitive information gets stored in databases. In fact, a central database is probably the most secure way to store this data. Large enterprise databases have tons of functionality to do things like encrypt sensitive information, to audit who accesses it, to limit or prevent people including DBAs from viewing the data, etc. You can have ...


38

You need to back up a couple steps and, in consultation with your client, work out a threat model. (Yes, that's a link to a 600-page book; yes, I am seriously recommending you read the entire thing.) A threat model starts by asking questions like Why does the app need to store this sensitive data in the first place? Can you avoid storing it at all? Can ...


35

This is an oddly phrased question that is really, really broad if answered fully. I'm going to focus on clearing up some of the specifics that you're asking about. Immutability is a design trade off. It makes some operations harder (modifying state in large objects quickly, building objects piecemeal, keeping a running state, etc.) in favor of others (...


22

The only difference between the two is the synchronization used in StringBuffer. The overhead of synchronization is not huge in the grand scheme of things, but it is significant relative to the StringBuilder methods that don't have them. The JVM is doing work that it wouldn't otherwise have to do--especially with only one thread, etc. If your code works ...


22

In my opinion, this is a fabulous interview question -- at least assuming (1) the candidate is expected to have deep knowledge of threading, and (2) the interviewer also has deep knowledge and is using the question to probe the candidate. It's always possible that the interviewer was looking for a specific, narrow answer, but a competent interviewer should ...


21

It sounds to me like they are leading you toward a semaphore solution. Semaphores are used to signal another thread that it's their turn. They are used much less frequently than mutexes, which I guess is why they think it's a good interview question. It's also why the example seems contrived. Basically, you would create m semaphores. Each thread x waits ...


16

Interview questions are sometimes actually trick questions, intended to make you think about the problem that you're trying to solve. Asking questions about a question are an integral part of approaching any problem, whether it's in the real world or in an interview. There are a number of videos circulating the internet on how to approach questions in ...


15

The usual solution for knowing "which change is correct" is a vector clock. You essentially keep track of counters for each repository that holds the data, and reject changes if a particular client's view of everyone else's state differs from that of the peer it is connecting to. The big question that you have to answer is how you'll resolve rejected saves. ...


13

A function that accepts some value and returns some other value, and doesn't disturb anything outside of the function, has no side effects, and is therefore thread-safe. If you want to consider things like how the way the function executes affects power consumption, that's a different problem. I am assuming that you're referring to a Turing-complete ...


12

Is there any algorithm that must use one of them in its implementation? Almost certainly not. (Indeed, from the theoretical perspective, you should be able to simulate wait / notify using other java.util.concurrent.. classes. And synchronized could be replaced with explicit Lock operations ... though you would need to be careful to unlock in finally ...


12

Synchronize on the Person.class or create a static LOCK object on which you synchronize: synchronize(Person.class){ //... } or private static final Object LOCK = new Object(); //... synchronize(LOCK){ //... } Either way, we're using a single (static) lock object instance which is common to all callers. Synchronizing on the class mirrors the ...


12

In Java, synchronized locks are re-entrant. Or in other words if your thread already holds the lock on an object it doesn't have to wait on itself.


12

Transactions A transaction wraps all of the required steps for a particular business operation and guarantees that either all of the steps succeed or they all rollback to the original state in the database before the transaction was started. Further Reading How are Cassandra transactions different from RDBMS transactions?


11

This is pretty much what I have been doing or a living the past few years, and my gut instinct is that the time to read 500,000 items from the source database and sync in the destination will not take as much time as one might think and the time taken to read the "key" fields, compute the MD5 hash, and cross check with your table to avoid syncing items that ...


10

This is the Byzantine Generals problem, which is unsolvable. You can never guaranteed synchronize the two servers if you cannot guarantee that at some time in the future, you will have sufficient reliable bandwidth to perform the synchronization all in one go.


9

If you read carefully the documentation of synchronized you will find that it is explicitly stated that once a thread has acquired a lock, it is allowed to re-acquire it as many times as it pleases. According to the Java Language Specification: Section 8.4.3.6. "synchronized Methods" says that the synchronized keyword acquires a monitor. See: http://docs....


9

There's actually quite a bit you can do to recover something close to the actual time of most of your events. Android gives you a few useful tools to work with, notably broadcast intents sent when the device completes a boot, when the system clock changes and when a shutdown is imminent. It also gives you a way to check the amount of real time that's ...


9

You have missed the point of async/await It wasn't created to frustrate developers with deadlocks. It was created to free up Processing power while we wait for a non CPU based task to complete. The lack of synchronisation context in dotnetcore might save you from unexpected deadlocks, but it also means you have to worry about thread starvation. Everytime ...


8

On Windows there's a mechanism to have the OS alert you when there's a change to a 'watched' directory structure - FindFirstChangeNotification(). When that indicates a file has changed, an application can then go about comparing files in the changed directory to find the actual files that have changed by looking at size, modified date, hash, etc. This (as ...


8

Promises were made to solve problems like this; they work really well in functional languages (I've personally used them extensively in Javascript, where curiously jQuery actually has the worst implementation of them - see this comparison). The weird thing about using promises is accepting that things are easier when you make everything use them. I will ...


8

One option to do the synchronization would be to do it peer-to-peer. This will still require a central server, but that server won't handle any of the data. When a device goes online, a central server gets a notification with the user-id. When a second device of the same user goes online, the server sends both devices the IP addresses of the other. The ...


7

You can abstract the transaction as an object in itself, which then provides a single interface to manage the transaction and its participants. First property of transactions, Atomicity satisfies your requirement of atomicity/single point. I.e. something like this: public class Transaction { ... private Account _source; private Account ...


6

No, Dropbox and any decent synchronization tool relies on file system events. All operating systems offer such events and programs like Dropbox are just simply listening for changes on files they are watching. When a change happens, or file is added / deleted, Dropbox decides what it has to do. If several events happen while others are in progress, they a ...


6

First, as the comments point out, you aren't really talking about realtime here -- that has a pretty strict definition and implies lots of stuff that isn't really on the table. You are talking about connecting two systems in a near realtime sort of manner. Anyhow, yes, the best bet would be some sort of message queueing solution here. The POS system would ...


6

This is either fundamentally meaningless or you've left out an important detail. Your diagrams give each node 3 states: ● Unchanged, don't propagate ◌ Just now changed and in need of propagation ○ Old change, don't propagate But in the end it all goes back to ● unchanged. So nothing is learned. Which makes me think it's not really the same state as we ...


5

I'm inclined to agree with you for the reasons you state. Also, if you use the same database, you also get a very practical business benefit - you can easily 'upgrade' a customer to the full version without a complicated data export/import. One thing you might recommend is trying it first with the one database approach. If that becomes a problem, its far ...


5

Since what you are really talking about here is a stylistic/readability issue (at least, that's the way I read it), you might be a little out of luck, because all the all alteratives I can think of aren't great. Really you have two options, write multiple distinct functions like you have done above, or use closures to bring it all "inline" (as it were), ...


5

You need to do this based on what you actually see in your system. The two basic approaches are to do it once or to make your code adjust on the fly. The first is obviously a lot easier to do but somewhat less resilient. Doing it once means logging the time difference for each pair of servers for a while and seeing what you get. This might take a while, ...


5

According to EBU Recommendation R37: “The relative timing of the sound and vision components of a television signal” states that end-to-end audio/video sync should be within +40ms and -60ms (audio before / after video, respectively) and that each stage should be within +5ms and -15ms. This quote is the summary from the Audio to video synchronization ...


Only top voted, non community-wiki answers of a minimum length are eligible