Tuesday, August 24, 2021

Interview Preperation

Big O Notations

Programming Paradigms

OS

Race Condition

When two threads try to share resources and whoever gets first other gets bad data like getting balance before withdrawal 

Deadlock

When two threads are waiting for the other to release the resource. now both threads are deadlocked.

thread A needs a Db connection which thread B has acquired lock on it and Thread B needs a File which A has locked. Now both be waiting for each other to release the locks.

Starvation

A thread is not able to acquire a resource that it wants to process because it is acquired by threads that have higher priority.

Mutex (mutual exclusive)

Semaphore

Live Lock

Livelock is a situation where a request for an exclusive lock is denied repeatedly, as many overlapping shared locks keep on interfering each other. The processes keep on changing their status, which further prevents them from completing the task. This further prevents them from completing the task.

Asynchronous 

When a program sends any request to the lower-level control, HTTP, file read or database, etc It doesn't wait for it to finish but the thread continues to do its work. it doesn't block anything.

Multiprocessing 

Spin up multiple processes with their own memory and resources and divide tasks among them 

Multithreading

Threads are part of a process that has access to the same memory

Cooperative multitasking vs Preemptive multitasking

Preemptive scheduling has to solve a hard problem -- getting all kinds of software from all kinds of places to efficiently share a CPU.

Cooperative scheduling solves a much simpler problem -- allowing CPU sharing among programs that are designed to work together.

So cooperative scheduling is cheaper and easier when you can get away with it. The key thing about small devices that allows cooperative scheduling to work is that all the software comes from one vendor and all the programs can be designed to work together.


Performance Optimization

Latency: The time to completion of a task. Measured in time units.

Throughput: The number of tasks completed in a given period. Measured in tasks/time unit, typical seconds.


SOLID PRINCIPLES

OOP

Interfaces vs Abstract classes with C# 8

  • The interface is like a contract; you define to expose functionality however abstract class is an abstraction of some functionality or implementation. 
  • Interfaces can be multiply inherited and also structs can implement it but abstract class behaves like a class
  • The conceptually derived class is a specialization of parent class but interfaces represent a common contract of the functionality. ConsoleLogger will be common functionality used, enhanced or extended version of BaseLogger but ConsoleLogger will implement ILogger defined functions.
  • Interface Implementation is default implementation that means you can either use default implementation or override it but the abstract class's functionality is extendable.
  • Multiple interfaces could be implemented and relation shouldn't be necessary "is a" but single base class exists and relation should be "is a" with the base class.
  • avoid diamond problem, please 

Design Patterns

Database

RDMS: Relational database management system
Data Integrity: All data should be correct in all the ways we retrieve it. Preventing reduant data.
    Entity Integrity: Data should be there as it as suppose to be
    Domain Integrity: Column should have data which is expected.
    Relattion Integrity: relation should be integral 
Anomolies: Error in data integrity.

DDL: Data definition language
DML: Data Modification language

Atomic Values: Each column should have atomic values, one value in the column

Relationships

  • One to one: Either we keep column within same table or define foreign key in other table unique and not nullabke
  • One to many:  Foreign Key with in other table 
  • Many to many: A junction table with both tables ids in it.
Keys:

Super key: any number of columns ensure the uniqueness in the table
Candidate key: least number of columns to ensure uniqueness (Primary Key)
Foreign Key: Primary key of another table 
Surrogate Key; UserID, StoreId which has no real meaning in domain its surrogate key as primary key
Natural Key: A domain key as primary key
Simple Key: One column key
Composite/Compound Key: Multiple column key in the database

Modeling

ERD: Entity Relationship Diagram

Indexes

A clustered index is created when we defined PK on any column. Data is stored in a tree format and sorted by clustered index.

A non-cluster key is mapped as clustered-value in a tree. Once it finds the cluster key from the tree. now it can easily search on real data with a cluster key.





Operating Systems

.NET

Fundamentals

  • .NET apps run managed code in a runtime environment known as the Common Language Runtime (CLR).
  • The .NET CLR is a cross-platform runtime that includes support for Windows, macOS, and Linux. The CLR handles memory allocation and management. The CLR is also a virtual machine that not only executes apps but also generates and compiles code using a just-in-time (JIT) compiler.
  • Higher-level .NET languages, such as C#, compile down to a hardware-agnostic instruction set, which is called Intermediate Language (IL). When an app runs, the JIT compiler translates IL to machine code that the processor understands. JIT compilation happens on the same machine that the code is going to run on. So, On run time .net compiles the app and optimizes it too.
  • The default experience for most .NET workloads is the JIT compiler, but .NET offers two forms of ahead-of-time (AOT) compilation: iOS needs full AOT and ReadyToRun where dotnet produces ready to run if you describe ReadyToRun to True, OS and Processor too.

Working with unmanaged resources

Sometimes code needs to reference unmanaged resources. Unmanaged resources are resources that aren't automatically maintained by the .NET runtime. For example, a file handle is an unmanaged resource. A FileStream object is a managed object, but it references a file handle, which is unmanaged. When you're done using the FileStream, you need to explicitly release the file handle.

In .NET, objects that reference unmanaged resources implement the IDisposable interface. When you're done using the object, you call the object's Dispose() method, which is responsible for releasing any unmanaged resources. The .NET languages provide a convenient using statement (C#F#VB) that ensures the Dispose method is called.


  • Source code (.cs) files are compiled into MSIL (Microsoft Intermediate Language) also known as CIL (Common Intermediate Language) or IL (Intermediate Language) along with its metadata. MSIL is machine independent.
  • Metadata includes programming language, environment, version, and class libraries  types, members, and references in your code.
  • CLR contains JIT(Just In Time) compiler which converts MSIL to machine code to be executed on current machine.
  • The MSIL code is only the managed code which CLR manages; everything else is called unmanaged code outside of scope of CLR (win32 apis, COM components) managed by OS.
  • Common Type System (CTS) understands all the language types and translates it to the CLR. Reference types; allocates memory in the runtime and into the heap and Value Types; stored in the stack and memory is allocated at compile time.
  • CLR helps common execution environment for more than 60 .Net Languages, memory management i.e garbage collection, sharing code and libraries across the languages, 
  • The Common Language Runtime in the .NET Framework is the Virtual Machine component that handles program execution for various languages such as C#, F#, Visual Basic .NET, etc. The managed execution environment is provided by giving various services such as memory management, security handling, exception handling, garbage collection, thread management, etc.
For more details refer geekscode, msdn, msdn terms

What is Heap and what is Stack?

  • Both are memory locations, wherein Heap is global and Stack is local.
  • The Heap is application-level while the Stack is thread-level.
  • The Stack has a defined first-in-first-out stack structure, while the Heap does not have a defined data structure.
  • Its size is defined at the time of its creation. For Heap, the size is defined when starting the application and for Stack, when creating a thread.
  • Both can grow dynamically.
  • The Stack is faster than the Heap. A stack is in “cache” and doesn’t have to synchronize with other threads like the Heap.
  • The Stack stores values while the Heap stores objects.
Dotnet used managed heap, which is different from the heap OS provided. Managed heap is allocated on start of the application.

Roslyn (Library, API): Compiles, Provide Diagnostic, Analyze Code. 

Compile Time Vs Run Time

C#

Types

Reference types are stored in managed head and value types are stored in stack.

Value Types

  • Value types are sealed
  • All primitive types, enums and structs are value types.

Reference types

  • A type that is defined as a classdelegate, array, or interface is a reference type
  • On Declaration they have value of null by default

Nullable types

Ordinary value types can't have a value of null. However, you can create nullable value types by appending a ? after the type. For example, int? is an int type that can also have the value null. Nullable value types are instances of the generic struct type System.Nullable<T>. Nullable value types are especially useful when you're passing data to and from databases in which numeric values might be null. For more information, see Nullable value types.



Indexers (C# Programming Guide)

Indexers allow instances of a class or struct to be indexed just like arrays. The indexed value can be set or retrieved without explicitly specifying a type or instance member. Indexers resemble properties except that their accessors take parameters.

using System; class SampleCollection<T> { // Declare an array to store the data elements. private T[] arr = new T[100]; // Define the indexer to allow client code to use [] notation. public T this[int i] { get { return arr[i]; } set { arr[i] = value; } } } class Program { static void Main() { var stringCollection = new SampleCollection<string>(); stringCollection[0] = "Hello, World"; Console.WriteLine(stringCollection[0]); } }

Entity Framework Core

Entity Framework (EF) Core is an open source and cross-platform data-access technology that can serve as an ORM. EF Core lets you work with a database by referring to .NET objects in code. It reduces the amount of data-access code you would otherwise need to write and test. EF Core supports many database engines.

For more information, see Entity Framework Core and Database Providers.

LINQ

Language-integrated query (LINQ) lets you write declarative code for operating on data. The data can be in many forms (such as in-memory objects, a SQL database, or an XML document), but the LINQ code you write typically doesn't differ by data source.

For more information, see LINQ (Language Integrated Query) overview.

ASP.NET

WebAPI

SOAP: 

soap has built-in retry logic, has WS security built-in, has WSDL file for function definition

Rest API: A Design Approach


HTTP communication between software, it has verbs to communicate what to do, end points to identify where and headers to communicate more information 

Verbs

GET, POST, PUT, PATCH, DELETE, COPY, HEAD, OPTIONS, LINK, UNLINK, PURGE, LOCK, UNLOCK, PROFIND VIEW

Best Practises

0. Stateless
1. JSON Data format
2. Use nouns (not GetUser but Users and use Post endpoint, not delete book instead books with verb delete)
3. User plurals (Users, Books)
4. Use HTTP Error Codes (500, 200, 404, 201)
5. Paging, Filtering, Sorting of getting Collection
6. versioning localhost/v1/orders
7. Docs (Swager)
8. Using SSL, TLS (HTTPS) 


Throating

Rate limiting: Number of requests per user in a given time
IP Level Throttling: No. of request per IP
Concurrent Level: no. of concurrent request per client
Resource Level: DB/Particular resource throttling

Authentication/Authorization

Session Based Authentication usually implemented as cookie in browser. client sends key for the particular session which server has generated when client provides its credentials. Invalidate session when logs out
State based session: server has to remember the sessions that means redis cache, or some memory to remember this.

Basic Authentication: Client needs to send username and password everytime. Its stateless
In the Authorization Headers: username:password, and encode base64 
You send Basic <encoded value of username:password>
The reason we are encoding because if there is non-http compitable it should be encoded.

Digest Access Authentication: Encrypted Token

Asymetric Cryptograpgy Authentication: Encrypted Token can only be decrypted by server

OAuth

Standard to grants, authenticate multiple clients etc Imlimenr single sign on, multiple websites to login

JWT (Json web tokens)
Signed token with all the clients information; when customer returns we verify sign.

Angular

Ajax

Javascript

HTTP

CSS

HTML


Microservices

Event Driven Archetecture

Cloud Archetecture


TDD

Unit Test

Integration Test

Functional Test

BDD

Cache

Queues



Version Control

CI/CD

MSBuild and the .NET CLI can be used with various continuous integration tools and environments, such as:

Azure
Docker
Encryption and Hashing
Idempotency

Agile Programming
Encryption

System Design Concept

1. Load-balancing 2. Caching 3. Database schema design 4. Slave-master replications 5. Database sharding 6. API design

No comments:

Post a Comment