Microsoft Interview Question for Interns


Country: India




Comment hidden because of low score. Click to expand.
4
of 4 vote

There are two ways of locking database - Pessimistic and Optimistic.

Pessimistic used:
In the banking application example, an account is locked as soon as it is accessed in a transaction. Attempts to use the account in other transactions while it is locked will either result in the other process being delayed until the account lock is released, or that the process transaction will be rolled back. The lock exists until the transaction has either been committed or rolled back.

If Optimistic is used :
In the banking application example, the amount of an account is saved when the account is first accessed in a transaction. If the transaction changes the account amount, the amount is read from the store again just before the amount is about to be updated. If the amount has changed since the transaction began, the transaction will fail itself, otherwise the new amount is written to persistent.

I have taken this from wiki : Please read complete article from
wiki/Lock_(database)

- Ashay Raut August 07, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Critical section.

- DashDash July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

+1. Or database isolation level of serializable.

- Noobie July 29, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Generating a key for every single account.
One person will be holding that key unless his transaction is complete.
Then key will shift to next user of the same account.
Hope it will be fine

- Roxan July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Suppose two joint account holders try to withdraw some amount at the same time.
The withdrawal process should be a critical section. The other person can specify his requirements (about how much to withdraw) and can even click on "OK" button to debit, but his machine shouldn't render any money as long as the first person's transaction is not complete and there is still enough money in account to cater second withdrawer's request.

The lock should be obtained as soon as "OK" button is clicked.

- Learner July 29, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Most times, when you are worried about corruption due to two processes happening simultaneously, it is common to lock down the thread when the first process begins.In this case, I would design it so that when someone is making a withdrawal or deposit on the account, it would lock down the account (typically using a mutex of some sort) and limit the other user to only being able to view the balance or other things that don't actually change the state of the account. Also, for end user knowledge/experience, I would display a warning stating that this account is in use at another location and therefore, the balance may not be up to date. Once the first person was done, the account would be released so that the other user could then conduct their business

- Ken August 13, 2013 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More