synovise interview Flashcards
What is the difference between synchronous and asynchronous programming, and when would you choose one over the other?
synchronous is a single thread of execution which runs from start to finish and doesn’t run the next set of code until the previous is finished whereas asynchronous will branch off and execute code in new threads of execution while continuing to run the initial thread and handle any additional threads with their completion callbacks. Synchronous is used when a task requires all results before continuing like logging in and asynchronous is used when an application is running and something like data needs to be retrieved or a secondary task needs to be completed.
How would you handle database transactions and ensure data consistency in a multi-threaded application?
make sure all transactions are atomic so that they all succeed or none of them do, table locking to ensure any inserts or updates are completed before any other actions start, and constraints on the table data to endure correct relations and data formats.
Explain the concept of dependency injection and how it can benefit software development.
You specify the data dependencies that are needed in a constructor, interface, or setter so that the object or class is not responsible for also implementing those data designs themselves. The data structure can then be maintained outside of the implementation and allow for better individual testing, reducing code size, and allows for reusability and modification. (apiservice example)