Interview Backend Questions

General Questions

Table of Contents

  1. Explain SOLID
  2. Explain Abstraction
  3. Explain Polymorphism concept in computer science
  4. Explain Single Responsibility with examples
  5. Explain Design Pattern
  6. Design Pattern you know and used before
  7. Explain Async, Sync
  8. Proxy Servers
  9. What are Multi-Tenant Servers
  10. Why we need Tokens for authentication
  11. Authentication vs Authorization
  12. Monolith vs Microservices
  13. What is a Load Balancer and its importance?
  14. How Can I enhance the API and reduce API response time?
  15. Difference between proxy and reverse proxy

Database Questions

Table of Contents

  1. Explain ACID concept
  2. What is an ORM and when/why to use it
  3. Database indexing (explain/when to use/tradeoffs)
  4. What is a database view
  5. Explain Database transaction
  6. SQL vs NoSQL
  7. Difference Between DELETE and TRUNCATE
  8. What is a lock and why is it useful?
  9. Explain Join in Database
  10. Difference Between Cluster/Non-Cluster Index
  11. What is Elasticsearch and when to use it and explain its tradeoffs
  12. How does Database Normalization improve design?
  13. How can I enhancement the SQL query?
  14. What is the innodb?
  15. Function vs stored procedure

Git Questions

Table of Contents

  1. What is git fetch vs. git pull
  2. What is a Git tag, and why is it used?

Django & Python Questions

Table of Contents

  1. Explain Django's MVT architecture
  2. How does Python's GIL (Global Interpreter Lock) work?

PHP Laravel Questions

Table of Contents

  1. Explain the Eloquent ORM in Laravel
  2. What are Middlewares in Laravel?
  3. Explain Laravel lifecycle
  4. Define N+1 Problem and How we can solve it
  5. What is the service container?
  6. What is the service provider?
  7. What is the composer?
  8. What are jobs and when we use them?
  9. What is dependency injection?

Q&A

Explain SOLID

Q: Explain SOLID principles. A: SOLID is an acronym for five design principles intended to make software designs more understandable, flexible, and maintainable. The principles are Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion.

Explain Abstraction

Q: Explain Abstraction. A: Abstraction in computer science is a method of reducing complexity and allowing efficient design and implementation in complex software systems by hiding the technical complexity and only showing the essential features of the object.

Explain Polymorphism concept in computer science

Q: What is polymorphism in computer science? A: Polymorphism is a fundamental concept in object-oriented programming that allows objects to be treated as instances of their parent class, enabling a single interface to handle different underlying data types. There are two main types: compile-time (or static), which includes method overloading, and run-time (or dynamic), which involves method overriding through inheritance.

Explain Single Responsibility with examples

Q: What does Single Responsibility Principle (SRP) mean and can you provide an example? A: The Single Responsibility Principle is one of the SOLID principles which states that a class should have only one reason to change, meaning it should perform a single kind of duty. For example, a class InvoiceProcessor should handle invoice processing, but not the invoice's persistence to a database; the latter should be handled by another class like InvoiceRepository.

Explain Design Pattern

Q: What is a design pattern in software engineering? A: Design patterns are typical solutions to common problems in software design. They serve as templates that can be applied to real-world programming issues. Patterns are categorized into Creational, Structural, and Behavioral types, each addressing different aspects of design challenges.

Design Pattern you know and used before

Q: What design patterns have you used? A: I've frequently used the Singleton pattern for ensuring only one instance of a class is created, the Observer pattern to enable a subscription mechanism to notify multiple objects about any events that happen to the object they are observing, and the Factory Method pattern which provides an interface for creating objects but allows subclasses to alter the type of objects that will be created.

Explain Async, Sync

Q: What is the difference between asynchronous and synchronous programming? A: In synchronous programming, tasks are performed one after another, each task starting only after the previous one has finished. Asynchronous programming allows a task to be initiated and then put aside until a later time while other tasks run in the meantime, improving the efficiency of application execution.

Proxy Servers

Q: What are proxy servers and how do they work? A: Proxy servers act as intermediaries between a client and a server, forwarding client requests to the server and then returning the server's response to the client. This provides increased privacy and security and can also be used to cache data to improve load times.

Explain Polymorphism concept in computer science

Q: What is polymorphism in computer science? A: Polymorphism is a fundamental concept in object-oriented programming that allows objects to be treated as instances of their parent class, enabling a single interface to handle different underlying data types. There are two main types: compile-time (or static), which includes method overloading, and run-time (or dynamic), which involves method overriding through inheritance.

Explain Single Responsibility with examples

Q: What does Single Responsibility Principle (SRP) mean and can you provide an example? A: The Single Responsibility Principle is one of the SOLID principles which states that a class should have only one reason to change, meaning it should perform a single kind of duty. For example, a class InvoiceProcessor should handle invoice processing, but not the invoice's persistence to a database; the latter should be handled by another class like InvoiceRepository.

Explain Design Pattern

Q: What is a design pattern in software engineering? A: Design patterns are typical solutions to common problems in software design. They serve as templates that can be applied to real-world programming issues. Patterns are categorized into Creational, Structural, and Behavioral types, each addressing different aspects of design challenges.

Another Answer: Design patterns are design level solutions for recurring problems that we software engineers come across often. It’s not code - I repeat, ❌CODE. It is like a description on how to tackle these problems and design a solution. Using these patterns is considered good practice, as the design of the solution is quite tried and tested, resulting in higher readability of the final code. Design patterns are quite often created for and used by OOP Languages, like Java, in which most of the examples from here on will be written.

Design Pattern you know and used before

Q: What design patterns have you used? A: I've frequently used the Singleton pattern for ensuring only one instance of a class is created, the Observer pattern to enable a subscription mechanism to notify multiple objects about any events that happen to the object they are observing, and the Factory Method pattern which provides an interface for creating objects but allows subclasses to alter the type of objects that will be created.

Explain Async, Sync

Q: What is the difference between asynchronous and synchronous programming? A: In synchronous programming, tasks are performed one after another, each task starting only after the previous one has finished. Asynchronous programming allows a task to be initiated and then put aside until a later time while other tasks run in the meantime, improving the efficiency of application execution.

Proxy Servers

Q: What are proxy servers and how do they work? A: Proxy servers act as intermediaries between a client and a server, forwarding client requests to the server and then returning the server's response to the client. This provides increased privacy and security and can also be used to cache data to improve load times.

What are Multi-Tenant Servers

Q: What are Multi-Tenant Servers?
A: Multi-tenant servers host multiple clients (tenants) on the same server infrastructure. Each tenant's data and applications are isolated but operate on shared resources like databases, compute resources, and storage systems. This architecture is cost-effective and efficient for managing large numbers of users, especially in cloud environments or SaaS (Software as a Service) applications, where scalability and resource optimization are crucial.

Why we need Tokens for authentication

Q: Why do we need Tokens for authentication?
A: Tokens, such as JWTs (JSON Web Tokens), are used in authentication to securely transmit information between parties as a JSON object. They are crucial because they allow the server to verify the token's validity without storing session information, thus supporting stateless authentication. Tokens enhance security by ensuring that the authentication information is protected with encryption and signatures and provide a scalable way to handle authentication across distributed systems.

Authentication vs Authorization

Q: What is the difference between Authentication and Authorization?
A: Authentication is the process of verifying who a user is, while authorization is the process of verifying what they have access to. Authentication typically precedes authorization; once a user's identity is confirmed through login credentials, biometrics, or tokens, authorization then checks whether they have the rights to access certain resources or perform specific actions within the system.

Monolith vs Microservices

Q: What is the difference between Monolith and Microservices architectures?
A: Monolith architecture involves building a single unified software application where all components are interconnected and interdependent. In contrast, Microservices architecture breaks down the application into smaller, independent services that communicate over a network. Microservices allow for easier scaling and better fault isolation, making it easier to update and maintain parts of the application without affecting the whole system. However, they can introduce complexity in terms of network latency and the management of distributed systems.

What is a Load Balancer and its importance?

Q: What is a Load Balancer and why is it important?
A: A Load Balancer is a device that distributes network or application traffic across multiple servers to enhance the efficiency, reliability, and capacity of service handling. It ensures no single server bears too much demand. By spreading the load, it helps prevent server overload, minimizes response time, and ensures a smoother distribution of workloads. It is vital for maintaining system performance and availability, especially in environments with high traffic or in distributed systems like microservices.

How Can I enhance the API and reduce API response time?

Q: How can I enhance the API and reduce API response time?
A: Enhancing API performance and reducing response times can be achieved through several strategies:

  1. Caching: Store frequently accessed data in cache to avoid unnecessary database queries.
  2. Optimize Queries: Ensure database queries are efficient and fetch only the necessary data.
  3. Use Content Delivery Networks (CDNs): Serve content from locations closer to the user to reduce latency.
  4. Load Balancing: Distribute incoming API requests across multiple servers to ensure no single server becomes a bottleneck.
  5. Asynchronous Processing: Handle tasks that are resource-intensive or time-consuming in an asynchronous manner.
  6. Code Optimization: Regularly profile and optimize your API’s codebase to remove bottlenecks.
  7. Database: Check Database Queries and enhancement it with several ways like define what i need to back in response , check joins and make normlization if it possible

Difference between proxy and reverse proxy

Q: Difference between proxy and reverse proxy? A: Both proxy servers and reverse proxies are intermediaries that manage network traffic flow, but they serve different purposes:

Proxy Server

  • Position: Sits in front of a client (like your computer).
  • Function: Routes client requests to other servers on the internet.
  • Benefits:
    • Security: Filters traffic and blocks malicious requests.
    • Caching: Stores frequently accessed resources to improve performance.
    • Access control: Restricts user access to certain websites.
    • Anonymity: Masks the client's IP address.

Reverse Proxy Server

  • Position: Sits in front of one or more web servers.
  • Function: Receives client requests, forwards them to the appropriate web server(s), and returns the responses to the client.
  • Benefits:
    • Load balancing: Distributes traffic evenly among multiple web servers for better performance and scalability.
    • Security: Implements security measures like SSL termination and authentication.
    • Caching: Caches frequently accessed resources to reduce load on web servers.

Here's a table summarizing the key differences:

Feature Proxy Server Reverse Proxy Server
Position In front of client In front of web servers
Traffic flow Client -> Proxy -> Server Client -> Reverse Proxy -> Server
Main purpose Security, caching, access control, anonymity Load balancing, security, caching

Database Answers

Explain ACID concept

Q: Explain the ACID concept.
A: ACID stands for Atomicity, Consistency, Isolation, and Durability. It is a set of principles that guarantee that database transactions are processed reliably and ensure the integrity of data within the database.

  • Atomicity ensures that each transaction is treated as a single unit, which either succeeds completely or fails completely.
  • Consistency ensures that a transaction can only bring the database from one valid state to another, maintaining database invariants.
  • Isolation ensures that concurrent execution of transactions leaves the database in the same state that would have been obtained if the transactions were executed sequentially.
  • Durability ensures that once a transaction has been committed, it will remain so, even in the event of power loss, crashes, or errors.

What is an ORM and when/why to use it

Q: What is an ORM and when/why to use it?
A: ORM (Object-Relational Mapping) is a programming technique used to convert data between incompatible type systems using object-oriented programming languages. It creates a "virtual object database" that can be used from within the programming language. There are several reasons to use an ORM:

  • Simplification of data access and manipulation compared to direct SQL queries.
  • Reduction in boilerplate code needed to implement data operations.
  • Database abstraction which allows switching underlying databases more easily.
  • Improved maintenance and data integrity by keeping the data access code clean and organized. ORMs are particularly useful in large applications with complex databases and numerous data manipulation operations.

Database indexing (explain/when to use/tradeoffs)

Q: Explain database indexing and when to use it, including tradeoffs.
A: Database indexing is a data structure technique used to quickly locate and access the data in a database table. Indexes are used to speed up the retrieval of data but can also lead to slower writes and increased storage use.

  • When to use: Indexing should be considered when the performance of SELECT queries needs to be improved, particularly on large datasets, or when specific data needs to be accessed frequently.
  • Tradeoffs: While indexes significantly improve query speed, they also require additional disk space and can slow down data insertion, updates, and deletions because each transaction requires the index to be updated.

What is a database view

Q: What is a database view?
A: A database view is a virtual table based on the result-set of an SQL statement. A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the database. Views can aggregate data from various tables and present it as if it were coming from a single table, thereby providing a simplified and secure method of querying data.

Explain Database transaction

Q: Explain a Database transaction.
A: A database transaction is a unit of work performed within a database management system against a database, and treated in a coherent and reliable way independent of other transactions. A transaction generally represents any change in a database. Transactions in a database environment have two main purposes:

  • To provide reliable units of work that allow correct recovery from failures and keep a database consistent even in cases of system failure.
  • To provide isolation between programs accessing a database concurrently. If this isolation is not provided, the programs' outcomes are possibly erroneous.

SQL vs NoSQL

Q: What is the difference between SQL and NoSQL databases?
A: SQL (Structured Query Language) databases are relational, table-based databases that use structured query language for defining and manipulating data. These databases are highly structured and provide ACID compliance, which makes them suitable for complex queries and transactions. NoSQL databases, on the other hand, are non-relational and can be document-based, key-value pairs, graph databases, or wide-column stores. They offer flexible schemas and scale horizontally, making them suitable for handling large volumes of unstructured data and for applications that require high performance and scalability.

Difference Between DELETE and TRUNCATE

Q: What is the difference between DELETE and TRUNCATE commands in SQL?
A: DELETE and TRUNCATE are both SQL commands used to remove records from a table, but they operate differently.

  • DELETE is a DML (Data Manipulation Language) command that removes rows one at a time and records an entry in the transaction log for each deleted row, thus allowing where-clause to be used to specify which rows to delete. It can be rolled back if used within a transaction.
  • TRUNCATE is a DDL (Data Definition Language) command that removes all rows from a table by deallocating the data pages used by the table, which makes it faster and uses fewer system and transaction log resources. However, it cannot be rolled back and does not allow for conditional deletions.

What is a lock and why is it useful?

Q: What is a lock and why is it useful in databases?
A: A lock in database systems is a mechanism to control concurrent access to data resources. Locks help maintain data integrity by preventing data from being read or written by multiple transactions at the same time, which can lead to data anomalies. Locks can be applied at different levels, such as on rows, tables, or databases. They are useful for ensuring that only one transaction can modify data at a time, preserving the ACID properties of database transactions, particularly the isolation aspect.

Explain Join in Database

Q: Explain what a Join is in a database.
A: A join in a database is an SQL operation used to combine rows from two or more tables based on a related column between them. There are several types of joins:

  • Inner Join: Returns rows when there is a match in both tables.
  • Left (Outer) Join: Returns all rows from the left table, and the matched rows from the right table; if there is no match, NULLs are used to fill in columns from the right table.
  • Right (Outer) Join: Returns all rows from the right table, and the matched rows from the left table; if there is no match, NULLs are used to fill in columns from the left table.
  • Full (Outer) Join: Returns rows when there is a match in one of the tables.

Difference Between Cluster/Non-Cluster Index

Q: What is the difference between Clustered and Non-Clustered Indexes?
A: The main difference between clustered and non-clustered indexes concerns how they store data and affect data retrieval:

  • Clustered Index: Alters the physical order of the table and sorts the table's data rows according to the index key. There can be only one clustered index per table because the data rows themselves are sorted in only one order.
  • Non-Clustered Index: Does not alter the physical order of the table and maintains a separate object within the table that points to the original table rows after searching with the index. A table can have multiple non-clustered indexes.

What is Elasticsearch and when to use it and explain its tradeoffs

Q: What is Elasticsearch and when to use it? What are its tradeoffs?
A: Elasticsearch is a powerful open-source search and analytics engine designed for horizontal scalability, reliability, and easy management. It is often used for log and event data analysis, real-time application monitoring, and full-text searching capabilities. When to use: Elasticsearch is ideal when you need to perform complex searches and aggregations rapidly, especially across large volumes of data. Tradeoffs: While Elasticsearch excels in search capabilities, it requires significant memory and computing resources, especially as data and query complexity grow. It can also be complex to maintain and scale properly, requiring careful planning and management.

How does Database Normalization improve design?

Q: How does Database Normalization improve design?
A: Database normalization is a systematic approach of decomposing tables to eliminate data redundancy (repetition) and undesirable characteristics like Insertion, Update, and Deletion Anomalies. It aims to reduce data redundancy and improve data integrity. Normalization involves dividing large tables into smaller (and less redundant) tables and defining relationships between them. The process results in a cleaner database design, which improves performance and maintains consistency through easier maintenance of data.

How can I enhancement the SQL query?

Q: How can I enhance SQL query performance?
A: Enhancing SQL query performance can be achieved through several best practices:

  1. Use specific column names in SELECT statements instead of using *.
  2. Implement proper indexing by creating indexes on columns that are frequently used in WHERE clauses and as JOIN predicates.
  3. Optimize joins by ensuring that joins are made on columns that are indexed or using the most restrictive conditions first.
  4. Avoid subqueries and inline views if possible; instead, use temporary tables and write multiple queries to break down complex logic into simpler steps.
  5. Use query performance tools such as EXPLAIN PLAN to analyze and understand how SQL queries are executed, which can help identify bottlenecks.

What is the innodb?

Q: What is InnoDB?
A: InnoDB is a storage engine for MySQL, designed to provide high reliability and performance when processing large data volumes. It supports ACID-compliant transactions, foreign keys, and row-level locking. InnoDB is the default storage engine for MySQL and is recommended for applications that require frequent read and write operations, require transaction support, and maintain full data integrity.

Git Answers

What is git fetch vs. git pull

Q: What is the difference between git fetch and git pull?
A: git fetch and git pull are both commands used to update the local copy of a repository from a remote.

  • git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn’t do any file transferring. It’s more like just checking to see if there are any changes available).
  • git pull on the other hand does that AND brings (copies) those changes from the remote repository.

The main difference is that git fetch can be considered a safe way to review changes before integrating them, while git pull does the fetch followed by a git merge to update the current branch with the latest version.

What is a Git tag, and why is it used?

Q: What is a Git tag, and why is it used?
A: A Git tag is a marker that is used to point to a specific commit in the history of the repository. Tags are typically used to mark release points (v1.0, v2.0, etc.), indicating important milestones in the project’s development. Unlike branches, which may change over time as new commits are added, a tag always points to the same specific commit, making them ideal for referencing specific versions of the code. Tags can be created for both release and pre-release versions, and they do not change once created.

Django & Python Questions

Explain Django's MVT Architecture

Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It follows the MVT (Model-View-Template) architecture, a variant of the commonly known MVC (Model-View-Controller) architecture. The MVT architecture is comprised of the following components:

  • Model: The model is the definitive source of information about your data. It contains the essential fields and behaviors of the data you’re storing. Django follows the DRY Principle. The goal is to define your data model in one place and automatically derive things from it.

  • View: The view acts as the bridge between the Model and the Templates. It controls what is shown to the user and how it is shown through querying the Model for data. Views in Django are more about the logic that gets processed on the data before being sent to the template.

  • Template: The template is a presentation layer which handles the user interface part completely. It defines how to display the information to be presented to the user, based on HTML.

The flow of control in Django is as follows:

  1. Django receives a request from a user.
  2. It consults the URL dispatcher which forwards the request to a view function associated with the requested URL.
  3. The view queries the model for specific data and passes data to the template.
  4. The template renders the data in the format written in HTML, which is then served to the user's browser.

How does Python's GIL (Global Interpreter Lock) work?

Python's Global Interpreter Lock (GIL) is a mutex that protects access to Python objects, preventing multiple native threads from executing Python bytecodes at once. This lock is necessary because CPython's memory management is not thread-safe. The GIL allows only one thread to execute in the interpreter at any one time, which means Python’s multi-threading is not suitable for CPU-bound tasks that need to execute in parallel on multiple CPUs.

Here's how it works:

  • When a thread wants to execute, it must wait to acquire the GIL.
  • Once a thread acquires the GIL, it can perform operations involving Python objects or call Python/C API functions.
  • After a fixed interval, the thread releases the GIL (voluntarily or when I/O operations are performed), allowing another thread to acquire it and execute.

The presence of the GIL means that threads may be appropriate for I/O-bound tasks where the program spends most of its time waiting for external events. However, for CPU-bound tasks that require heavy computation and need to run in parallel, multiprocessing is generally a better approach than multi-threading.

PHP & Laravel Answers

Explain the Eloquent ORM in Laravel

Q: Explain the Eloquent ORM in Laravel.
A: Eloquent is the default ORM (Object-Relational Mapping) included with Laravel. It simplifies interactions with databases by abstracting database interactions into PHP objects. Developers can perform database queries using expressive, intuitive syntax rather than SQL code. Eloquent supports relationships, eager loading, mutators, accessors, and many other ORM features, making it powerful yet easy to use for Laravel applications.

What are Middlewares in Laravel?

Q: What are Middlewares in Laravel?
A: Middleware in Laravel provides a convenient mechanism for filtering HTTP requests entering your application. They are used for examining and filtering HTTP requests, such as authenticating users, performing logging, CORS, or even enforcing maintenance modes. Middleware can be applied globally to all requests, or they can be assigned to specific routes.

Explain Laravel lifecycle

Q: Explain the Laravel lifecycle.
A: The Laravel lifecycle begins when the server receives a request. It is then directed to the public/index.php file, which serves as the entry point for all requests entering the application. This triggers the loading of all the framework's components by the service providers. Next, the request goes through several stages, including the global and route-specific middleware, until it reaches the router that dispatches the request to a controller action or a closure. After the response is created by the application, it is sent back through the middleware stack, allowing any post-processing before the response is finally sent to the user.

Define N+1 Problem and How we can solve it

Q: Define the N+1 Problem and how we can solve it.
A: The N+1 problem is a common issue in ORMs that occurs when the code needs to execute N additional database queries to fetch related data for each of an initial query's N results. For example, retrieving all blog posts and then fetching the author for each post in a separate query results in 1 (initial posts query) + N (one query for each post's author) database queries. This can be solved in Laravel using Eloquent's eager loading feature by specifying the related data to be loaded at the time of the initial query (e.g., Post::with('author')->get();), thus reducing the total number of queries to a constant number, usually one or two.

What is the service container?

Q: What is the service container?
A: The service container in Laravel is a powerful tool for managing class dependencies and performing dependency injection. It is essentially a container that holds the bindings between interfaces and their concrete implementations. Using the service container allows developers to centralize and standardize the way objects are constructed in their applications, making it easier to manage dependencies and promote loose coupling.

What is the service provider?

Q: What is the service provider?
A: Service providers in Laravel are the central place to configure and bootstrap your application. Every Laravel application has multiple service providers responsible for setting up the application's components, registering services in the service container, and performing any task necessary to prepare the application for use. They are a powerful tool for organizing and bootstrapping application-specific configurations, tools, and other functionalities.

What is the composer?

Q: What is the Composer?
A: Composer is a dependency management tool for PHP, used to manage the dependencies of PHP applications. It allows developers to specify the libraries their project depends on and it manages (installs or updates) them for you. Composer is integral to modern PHP development, enabling easy management of third-party packages and libraries, ensuring version control and dependency resolution are handled efficiently.

What are jobs and when we use them?

Q: What are jobs and when do we use them?
A: Jobs in Laravel are used to handle asynchronous processing, allowing the application to perform time-consuming tasks (like sending emails, processing files, etc.) in the background without blocking the user interface. Jobs can be pushed onto different queues with varying priorities to be processed by queue workers. Utilizing jobs helps improve the responsiveness of your application by offloading tasks that are not immediately necessary for the initial response to the user.

What is dependency injection?

Q: What is dependency injection?
A: Dependency injection is a design pattern used to implement IoC (Inversion of Control), allowing a program design to follow the Dependency Inversion Principle. The main goal of dependency injection is to reduce the coupling between software components. Instead of instantiating dependencies inside a class, these dependencies are provided to the class (typically through the constructor or setter methods). This makes classes easier to manage and test because they don't control the creation or finding of their dependencies.

Contributing to Q&A

To add a question and answer to this section:

  1. Add your question to the 'Table of Contents' with a link.
  2. Write your question and answer in the Q&A section following the format above.
  3. Make sure to test your changes to the README for proper formatting.