Interview Preparation
Interview Preparation
1. What is a database?
A structured collection of data stored electronically, managed by a DBMS
(Database Management System) for efficient access and manipulation.
2. DBMS vs. RDBMS?
2. SQL Queries
4. Indexing
7. Advanced Concepts
o Add indexes.
o Rewrite inefficient joins.
o Avoid SELECT *.
o Use EXPLAIN to analyze the query plan.
42. What is query caching?
Storing query results to reuse them, reducing execution time.
43. What is sharding?
Splitting a database into smaller chunks (shards) distributed across servers.
44. What is connection pooling?
Reusing database connections to reduce overhead.
45. What is database normalization vs. denormalization?
9. NoSQL
o Document (MongoDB).
o Key-Value (Redis).
o Column-family (Cassandra).
o Graph (Neo4j).
48. What is CAP theorem?
A database can only guarantee two of: Consistency, Availability, Partition
Tolerance.
49. What is eventual consistency?
Data propagates to all nodes eventually (used in AP systems like Cassandra).
50. When to use NoSQL vs. SQL?
1. What is PHP?
PHP (Hypertext Preprocessor) is a server-side scripting language used for
web development. It is embedded in HTML and executed on the server.
2. What is the difference between echo and print?
o echo: Can output multiple strings, faster, and does not return a value.
2. PHP Advanced
3. OOP Basics
4. OOP Advanced
5. Practical OOP
1. Laravel Basics
1. What is Laravel?
Laravel is a PHP web application framework that follows the MVC (Model-
View-Controller) architecture. It provides tools for routing, authentication,
caching, and more.
2. What is the MVC architecture?
2. Eloquent ORM
3. Blade Templating
4. Middleware
5. Advanced Laravel
applications.
Answer: Laravel is a free, open-source PHP web framework used for building web
applications. It follows the MVC (Model-View-Controller) architecture and provides
various features like routing, sessions, caching, and authentication.
Answer: Routing in Laravel defines the routes for handling requests to your
application. Routes are defined in the routes/web.php file and map URLs to specific
controller actions or closures.
Answer: Blade is Laravel's templating engine. It allows you to use PHP code within
your views, but with a cleaner and more readable syntax. Blade also supports
template inheritance, sections, and components.
Answer: Laravel migrations provide a version control system for your database.
They allow you to define database structures in PHP code, which can be shared
across teams. Migrations are created using php artisan make:migration.
Answer: The .env file is used to store environment-specific variables like database
credentials, API keys, and other sensitive information. This file helps manage
different configurations for local, staging, and production environments.
Answer: Service providers are the central place for binding classes into the Laravel
service container. They are used to register services, configure settings, and boot
functionality within the framework.
12. Explain the Laravel Service Container.
Answer: The service container is a powerful tool for managing class dependencies
and performing dependency injection. It allows you to bind and resolve classes,
interfaces, and services.
Answer: Laravel provides a powerful validation system that can be applied using
request validation or by using the Validator facade. You can define validation rules
and error messages that will be automatically handled for you.
16. What are Laravel Policies?
Answer: Laravel Policies are used for authorizing actions in your application. They
provide a central place for defining authorization logic, such as whether a user is
allowed to create, update, or delete a resource.
Answer: Laravel's event system allows you to subscribe and listen to various events
in your application. You can create custom events and listeners to handle actions
such as sending emails or updating logs when certain actions occur.
Answer: Laravel provides an Illuminate\Mail class for sending emails. You can
configure mail drivers (like SMTP or Mailgun) and use Mailable classes or the
Mail::send() method to send emails.
20. What is Laravel Passport?
Answer: Facades are static proxies to classes in the Laravel service container. They
provide a simple, expressive syntax for interacting with various services, like
database, caching, or mail.
Answer: The config directory contains various configuration files for your Laravel
application. These files allow you to configure services, middleware, and other
settings used throughout your app.
Answer: Laravel Collections provide a fluent, convenient wrapper for working with
arrays. They provide methods for transforming, filtering, and sorting data, making it
easier to work with arrays in a more expressive way.
Answer: Laravel provides a unified API for different caching systems (like Redis,
Memcached, and database). You can cache query results, views, or other data to
improve the performance of your application.
Answer: Artisan commands are built-in commands that help with common tasks
such as generating code, running migrations, and managing the application. They
can be extended to create custom commands.
28. What is Laravel's db:seed command used for?
Answer: The db:seed command is used to populate your database with sample or
default data. Seeders allow you to automate database population using the Seeder
classes.
Answer: The migrate:rollback command is used to reverse the last database migration,
effectively undoing any changes made by the migration.
Answer: Laravel provides a simple and expressive way to handle file uploads
through the Illuminate\Http\Request class. You can store uploaded files on local or
cloud storage and retrieve their paths easily.
Answer: Laravel Sanctum is a simple authentication system for SPAs (Single Page
Applications) and APIs. It provides a lightweight way to authenticate users using
API tokens.
32. How can you optimize a Laravel application?
Answer: Route model binding allows you to automatically inject the model instance
related to the route parameter. For example, if the route parameter is an id, Laravel
will automatically retrieve the associated model.
Answer: Policies in Laravel are used for authorizing user actions. They contain
methods for determining whether a user can perform specific actions on a resource,
such as creating, updating, or deleting a model.
Answer: Laravel automatically includes CSRF protection for all routes that use the
web middleware. The CSRF token is included in forms using @csrf and is validated on
form submission.
Answer: Laravel Mix is a tool for compiling and bundling frontend assets like
JavaScript and CSS. It provides a clean, fluent API for running Webpack commands
with minimal configuration.
Answer:
related models.
belongsTo: Defines an inverse one-to-many relationship, where the model
Answer: The validate() method is used to validate incoming HTTP request data. It
accepts validation rules and automatically redirects the user back with error
messages if the data does not meet the specified rules.
Answer: Laravel’s session provides a way to store user data across multiple
requests. It can be used to store user preferences, authentication data, or temporary
state.
Answer: Jobs are tasks that are pushed onto a queue for deferred processing.
Queues allow for asynchronous processing of tasks, such as sending emails or
processing videos, to improve application performance.
Answer: You can create custom validation rules by using the Validator::extend()
method or by creating custom rule objects that implement the
Illuminate\Contracts\Validation\Rule interface.
Answer: The App::make() method is used to resolve a class or interface from the
Laravel service container. It’s typically used for dependency injection when creating
instances of classes.
Answer: Collections are a wrapper for arrays and provide a fluent API for working
with data. They include methods for filtering, sorting, transforming, and
manipulating the data contained in the collection.
Answer: A seeder is used to populate the database with default data. Seeders are
typically used for testing or initial setup of the application data.
48. How can you prevent SQL injection in Laravel?
Answer: Laravel provides a Storage facade for managing file uploads. Files can be
stored locally or on cloud services like Amazon S3. You can store files using
Storage::put() or Storage::disk() methods.
Answer: Guards define how users are authenticated for each request. Laravel comes
with a basic session guard for web authentication and token guard for API
authentication.
Solid and design patterns
SOLID Principles:
1. What is SOLID?
Answer: SOLID is an acronym that represents five design principles aimed at improving
software design and making it more maintainable, flexible, and scalable. It stands for:
Answer: The Single Responsibility Principle states that a class should have only one
reason to change, meaning it should only have one job or responsibility. If a class is
responsible for more than one thing, it can become harder to maintain.
Answer: A class that handles both user authentication and data persistence would violate
SRP. These responsibilities should be separated into two distinct classes, one handling
authentication and the other handling data storage.
Answer: The Open/Closed Principle states that software entities (classes, modules,
functions) should be open for extension but closed for modification. This means you
should be able to add new functionality without changing the existing code.
5. Can you provide an example of OCP?
Answer: Using polymorphism, you can extend a class without changing its original code.
For instance, you could add new types of payment methods to a payment processor class
without modifying the original class, but by extending it.
Answer: The Liskov Substitution Principle states that objects of a superclass should be
replaceable with objects of a subclass without affecting the correctness of the program. In
simpler terms, subclasses should extend the behavior of the parent class without altering
its fundamental functionality.
Answer: If you have a class Bird with a method fly(), and then you create a subclass
Penguin which cannot fly, replacing a Bird with a Penguin breaks the functionality,
violating LSP.
Answer: The Interface Segregation Principle states that clients should not be forced to
depend on interfaces they do not use. In other words, it's better to have small, specific
interfaces rather than a large, general-purpose one.
Answer: If you have an interface IWorker with methods work() and eat(), it might not
be appropriate for all classes (e.g., Robot class) to implement eat(). You should create
separate interfaces like IWorkable and IEatable.
Answer: The Dependency Inversion Principle states that high-level modules should not
depend on low-level modules. Both should depend on abstractions. Additionally,
abstractions should not depend on details. Details should depend on abstractions.
11. What are the benefits of following SOLID principles?
Design Patterns:
Answer: The Singleton Pattern ensures that a class has only one instance and provides a
global point of access to it. It's commonly used for managing global resources like
database connections.
Answer: A database connection class where you want to ensure that there is only one
instance of the connection object throughout the application can be implemented using
the Singleton pattern.
16. What is the Factory Method Pattern?
Answer: The Factory Method Pattern defines an interface for creating objects, but it
allows subclasses to alter the type of objects that will be created. It decouples the
instantiation process from the client class.
Answer: If you have a Shape interface with create() method, the CircleFactory class
can implement the ShapeFactory interface and instantiate Circle objects, while a
SquareFactory class would instantiate Square objects.
Answer: The Abstract Factory Pattern provides an interface for creating families of
related or dependent objects without specifying their concrete classes. It is useful when
your system needs to be independent of how its objects are created, composed, and
represented.
Answer: The Factory Method focuses on creating one product type, while the Abstract
Factory is used to create families of related product objects. The Abstract Factory is
useful when you need to create multiple related objects.
Answer: The Builder Pattern separates the construction of a complex object from its
representation, allowing the same construction process to create different representations
of the object.
Answer: A CarBuilder class can be used to create various types of cars (sedans, SUVs)
by specifying attributes like engine, wheels, and seats. The Car class would represent the
final product.
22. What is the Prototype Pattern?
Answer: The Prototype Pattern allows for creating new objects by copying an existing
object (prototype), rather than creating new instances from scratch. It's useful for
avoiding performance hits due to object creation overhead.
Answer: The Adapter Pattern allows incompatible interfaces to work together. It acts as a
bridge between two interfaces, enabling classes with different interfaces to interact.
Answer: If you have a MediaPlayer interface and a VLCPlayer class that implements it,
you can use an Adapter class to adapt the MP4Player interface to work with
MediaPlayer.
Answer: The Decorator Pattern allows you to dynamically add behavior to an object
without altering its structure. It is typically used for adding responsibilities to individual
objects.
Answer: A Pizza object can be decorated with additional toppings (like cheese or
olives) using a PizzaDecorator, which adds additional behavior without modifying the
original Pizza class.
Answer: The Observer Pattern is used when one object (the subject) needs to notify
multiple objects (observers) about state changes. This is often used in event handling
systems.
28. Give an example of the Observer Pattern.
Answer: The Strategy Pattern defines a family of algorithms and allows them to be
interchangeable. This allows the algorithm to be selected at runtime, depending on the
context.
Answer: In a payment processing system, you can use the Strategy Pattern to choose
between different payment methods (Credit Card, PayPal) dynamically, based on the
user’s choice.
Answer: A remote control system that issues commands to various appliances (TV, AC,
Lights) can use the Command Pattern to store and execute the commands at a later time.
Answer: The Chain of Responsibility Pattern allows multiple handler objects to process a
request without knowing which handler will process it. Each handler in the chain either
processes the request or passes it to the next handler.
34. What is the State Pattern?
Answer: The State Pattern allows an object to change its behavior when its internal state
changes. This pattern is useful when an object must behave differently based on its
current state.
Answer: The Composite Pattern is used to treat individual objects and compositions of
objects uniformly. It allows you to work with groups of objects in the same way as
individual objects.
Answer: The Proxy Pattern provides an object representing another object. It acts as an
intermediary, controlling access to the real object.
Answer: The Flyweight Pattern is used to minimize memory usage by sharing objects
instead of creating new ones. It’s useful when many objects are similar in structure and
only a few properties need to differ.
Answer: The Memento Pattern is used to capture the internal state of an object so that it
can be restored later, without violating encapsulation. It's often used in undo/redo
functionality.
40. What is the Template Method Pattern?
Answer: The Template Method Pattern defines the skeleton of an algorithm, with steps
that can be implemented by subclasses. It allows subclasses to override certain steps of
the algorithm without changing the overall structure.
Answer: The Visitor Pattern allows you to define new operations on elements of an
object structure without changing the classes of the elements. It involves adding a visitor
class that can visit elements and apply operations.
Answer: The Builder Pattern is used to construct complex objects step by step. It allows
for creating different representations of an object using the same construction process.
Answer: The Singleton Pattern ensures that only one instance of a class exists, while the
Factory Pattern provides a way to create instances of different classes based on certain
conditions.
Answer: In Laravel, you might use the Factory Pattern to create different types of
notification channels (email, SMS, etc.) without modifying the core logic of your
notification system.
46. Why is the Adapter Pattern useful?
Answer: The Adapter Pattern allows you to integrate different systems or components
that would otherwise be incompatible, making it easier to add new features or extend
existing functionality.
Answer: The Singleton Pattern can make unit testing difficult, as it introduces a global
state that can be hard to mock. It can also create tight coupling between classes.
Answer: Examples include using the Observer Pattern in event-driven systems, the
Factory Pattern for creating UI components, or the Singleton Pattern for managing
loggers or database connections.
Answer: Design patterns can sometimes be overused or misapplied. It’s important to use
them when appropriate and ensure they don't add unnecessary complexity to the system.
Answer: You should avoid using design patterns when the problem you're trying to solve
is simple or doesn't require the additional structure provided by a pattern. Overuse of
design patterns can result in unnecessary complexity.
Database [chatgpt]
Database Basics:
1. What is a database?
Answer: A relational database stores data in tables that are related to each other based on
key fields. Data is organized into rows and columns, and SQL (Structured Query
Language) is used for querying and managing the data.
3. What is SQL?
Answer: A primary key is a unique identifier for each record in a database table. It
ensures that each record can be uniquely identified and is often used to establish
relationships between tables.
Answer: A foreign key is a field in a table that is a primary key in another table. It
establishes a relationship between two tables and ensures referential integrity.
6. What is normalization in databases?
1NF (First Normal Form): Ensures that all columns contain atomic values and each
record is unique.
2NF (Second Normal Form): Achieved by removing partial dependencies (when a non-
key column depends on part of a primary key).
3NF (Third Normal Form): Removes transitive dependencies (when a non-key column
depends on another non-key column).
BCNF (Boyce-Codd Normal Form): A stricter version of 3NF.
8. What is denormalization?
Answer: An index is a data structure used to improve the speed of data retrieval
operations on a database table. It works by providing quick access to rows based on the
values of one or more columns.
Answer:
Clustered Index: The data is physically stored in the table in the order of the index. A
table can have only one clustered index.
Non-clustered Index: The index is stored separately from the table data, and it contains
pointers to the actual rows in the table. A table can have multiple non-clustered
indexes.
Database Design:
Answer: A schema is a logical collection of database objects like tables, views, indexes,
and relationships. It defines the structure and organization of data in the database.
Answer: A database view is a virtual table that presents data from one or more tables. It
contains a stored query that retrieves data dynamically when queried but does not store
data itself.
Answer: A stored procedure is a set of SQL statements that can be executed as a single
unit. It is stored in the database and can be reused multiple times to perform repetitive
tasks or complex queries.
Answer: A trigger is a set of SQL statements that automatically executes or "fires" when
a specified event occurs on a table, such as an insert, update, or delete operation.
Answer:
COMMIT: Saves all changes made during the current transaction to the database.
ROLLBACK: Undoes all changes made during the current transaction.
Answer: Referential integrity ensures that relationships between tables remain consistent.
It ensures that foreign keys point to valid rows in the referenced table and prevents
orphan records.
Answer: A join is an SQL operation used to combine data from two or more tables based
on a related column. The most common types of joins are:
Answer:
UNION: Combines the results of two or more SELECT queries and removes duplicate
rows.
UNION ALL: Combines the results of two or more SELECT queries and includes all rows,
including duplicates.
Database Performance:
Answer: Database indexing improves the speed of data retrieval operations by providing
a fast lookup for rows in a table. It creates a data structure that allows quick searching
based on indexed columns.
Unique Index: Ensures that all values in the indexed column are unique.
Composite Index: An index that involves multiple columns.
Full-text Index: Optimized for searching large text fields.
Spatial Index: Used for geospatial data.
Answer:
Answer: Sharding is the process of splitting a large database into smaller, more
manageable pieces, called "shards," which are distributed across different servers. It is
used to improve scalability and performance.
Answer: Database replication involves copying and maintaining database objects, like
tables or entire databases, across multiple servers. It is used for high availability, load
balancing, and disaster recovery.
Answer: A deadlock occurs when two or more transactions are waiting for each other to
release locks, resulting in a standstill where none of the transactions can proceed.
Answer: Normalization reduces data redundancy and ensures data integrity but can slow
down complex queries. Denormalization, on the other hand, can improve read
performance by reducing the need for joins, at the cost of data redundancy.
30. What is the difference between a temporary table and a regular table?
Answer: ACID is a set of properties that ensure that database transactions are processed
reliably:
Answer: A materialized view is a precomputed table that stores the results of a query. It
can be refreshed periodically and is used to improve the performance of complex queries.
Answer: The CAP theorem states that a distributed database system can achieve at most
two of the following three guarantees:
Consistency: All nodes see the same data at the same time.
Availability: Every request receives a response (success or failure).
Partition Tolerance: The system can continue to function despite network partitions.
Answer: Database partitioning involves splitting a large database into smaller, more
manageable parts (partitions). This can be done horizontally (by rows) or vertically (by
columns) to improve performance and scalability.
35. What is a database trigger?
Answer: A database trigger is a set of actions that are automatically executed when
certain events (e.g., insert, update, or delete) occur on a table or view. Triggers are used
for enforcing business rules, auditing, and other tasks.
Answer: A connection pool is a collection of database connections that are kept open and
ready for use by multiple clients or threads. It helps to improve performance by reducing
the overhead of repeatedly opening and closing connections.
Answer: A surrogate key is an artificial key created for a table, often as an auto-
incrementing integer. It is used as a unique identifier for a record when no natural key
exists or when the natural key is too complex.
Answer: NoSQL databases are non-relational databases that store data in a variety of
formats such as key-value, document, columnar, or graph. They are designed for
scalability and flexibility, especially for unstructured or semi-structured data.
41. What is the difference between SQL and NoSQL?
Answer:
SQL: Relational, uses structured tables with fixed schemas, and follows ACID properties.
NoSQL: Non-relational, more flexible schema, and often optimized for scalability and
high availability.
Answer: NoSQL databases are highly scalable, flexible, and performant, especially for
handling large volumes of unstructured or semi-structured data. They are designed to
handle big data, real-time analytics, and complex, high-velocity data.
Answer: CAP theorem states that a distributed database system can only achieve two of
the following three guarantees:
Consistency: All nodes see the same data at the same time.
Availability: Every request gets a response (either success or failure).
Partition Tolerance: The system can tolerate network partitions and still function.
Answer: MongoDB is a popular NoSQL database that stores data in a JSON-like format
called BSON. It is designed for horizontal scaling, high availability, and handling
unstructured data.
Answer: ACID compliance ensures that database transactions are processed reliably,
guaranteeing properties like atomicity, consistency, isolation, and durability for all
operations.
46. What is a database cluster?
Answer: A deadlock occurs when two or more database transactions are blocked because
each is waiting for a resource that the other has locked. It results in a standstill where
none of the transactions can proceed.
Answer: A table is a physical storage structure that holds data, while a view is a virtual
table created by querying one or more tables. A view does not store data but provides a
dynamic result set based on the query.
Answer: Web application security refers to the practices, tools, and measures taken to
protect web applications from threats and vulnerabilities, ensuring the confidentiality,
integrity, and availability of data and services.
Answer: XSS is a vulnerability that allows attackers to inject malicious scripts into web
pages viewed by other users. The malicious scripts can execute in the victim's browser,
potentially stealing cookies, sessions, or redirecting users to malicious websites.
Answer: SQL injection occurs when an attacker manipulates an SQL query to execute
malicious SQL code. This can lead to unauthorized access to a database, data theft, or the
destruction of data.
Answer: CSRF is an attack where a malicious website tricks a user’s browser into
making unwanted requests to a web application where the user is authenticated. This can
lead to unauthorized actions being performed on behalf of the user.
Answer: A security token is a unique identifier used in web applications to verify the
identity of users, authenticate requests, and prevent unauthorized access. It can be in the
form of a session token, API key, or a token-based authentication mechanism like JWT
(JSON Web Token).
6. What is the purpose of HTTPS?
Answer: A secure password policy defines the requirements for creating strong
passwords, such as a minimum length, a mix of uppercase and lowercase letters,
numbers, and special characters, and periodic password changes.
8. What are HTTP headers, and why are they important for security?
Answer: HTTP headers are metadata sent with HTTP requests and responses. Security-
related headers like X-Content-Type-Options, Strict-Transport-Security, and X-
XSS-Protection help prevent various attacks such as XSS, clickjacking, and man-in-the-
middle attacks.
Answer: PoLP is a security concept where users or systems are given only the minimum
permissions necessary to perform their tasks. This reduces the attack surface by limiting
the potential damage of compromised accounts or systems.
Answer: MFA requires users to provide multiple forms of verification (e.g., something
they know like a password, something they have like a phone, or something they are like
a fingerprint) before granting access, adding an extra layer of security.
Types of Web Security Threats:
Answer: A MitM attack occurs when an attacker intercepts and potentially alters the
communication between two parties (e.g., between a user and a server) without their
knowledge, often using it to steal sensitive information like login credentials.
Answer: Session hijacking is an attack where the attacker steals or guesses a valid
session token (often through XSS or sniffing) and uses it to impersonate the user and gain
unauthorized access to the application.
Answer: Clickjacking is an attack where a malicious website tricks a user into clicking
on something different from what they perceive. It is usually done by hiding malicious
elements within transparent frames or layers.
Answer: RCE is a critical vulnerability where an attacker can execute arbitrary code on a
server or system remotely. This can result in the full compromise of the server, often
leading to data breaches or system control.
16. What are the most common HTTP methods, and which ones should be avoided for
sensitive actions?
Answer: An SQL injection payload is a piece of malicious SQL code that an attacker
injects into an input field, URL parameter, or HTTP header to alter the behavior of an
SQL query. It can be used to retrieve, alter, or delete data.
Answer:
Stored XSS: Malicious scripts are stored on the server (e.g., in a database) and executed
when other users load the page.
Reflected XSS: The malicious script is reflected off the server immediately in the
response, usually via URL parameters or form inputs.
Answer: Input validation ensures that the data received from users or external sources is
clean, safe, and conforms to expected formats. Proper input validation helps prevent
attacks like SQL injection and XSS by filtering out harmful data.
Answer: CSP is a security feature that helps prevent XSS attacks by specifying which
content sources (scripts, styles, etc.) are allowed to run on a webpage. It can block
unauthorized external resources from being executed.
Authentication and Authorization:
Answer: OAuth is an open standard for authorization that allows third-party applications
to access a user's resources without exposing their credentials. It uses tokens to grant
limited access to resources on behalf of the user.
Answer:
Answer: A session cookie is a small piece of data stored in a user's browser that
identifies the user’s session. It is used to maintain the user's login state across multiple
requests.
24. What are JWT tokens, and how are they used in web security?
Answer: JWT (JSON Web Tokens) are compact tokens used to securely transmit
information between parties. They are often used in stateless authentication systems to
represent user identity and access privileges.
Answer: RBAC is a security model where access to resources is determined by the user's
role within an organization. Roles define the level of access to various resources or
actions within the system.
26. What are secure cookies, and how do they improve security?
Answer: Secure cookies are cookies that are only transmitted over HTTPS connections
and cannot be accessed by client-side JavaScript (when the HttpOnly flag is set). This
prevents cookies from being intercepted or stolen via XSS.
Answer: 2FA is a security method that requires two forms of verification to grant access
to an account. Typically, this involves something the user knows (password) and
something the user has (e.g., a phone or authenticator app).
Answer: CSRF protection involves using tokens to verify that requests originate from
authenticated users. A common method is embedding a unique CSRF token in forms,
which the server checks before processing requests.
Answer: HTTPS encrypts the communication between the user’s browser and the server
using SSL/TLS, preventing man-in-the-middle attacks, data theft, and eavesdropping. It
is essential for secure transmission of sensitive data.
Answer: A WAF is a security system designed to monitor, filter, and block HTTP traffic
to and from a web application. It helps protect against common attacks such as XSS, SQL
injection, and DDoS.
Answer: Input sanitization is the process of cleaning or filtering user input to prevent
malicious code from being executed. This can involve removing or escaping characters
that may be used in injection attacks.
Answer: Rate limiting controls the number of requests a user or client can make to a
server within a specified time frame. It helps mitigate DDoS attacks and brute-force login
attempts.
37. What are security patches, and why are they necessary?
Answer: Security patches are updates provided by software vendors to fix vulnerabilities.
They are crucial for protecting web applications from new and existing threats and
ensuring that attackers cannot exploit known flaws.
Answer: The OWASP Top 10 is a list of the ten most critical web application security
risks. It includes risks like injection, broken authentication, and sensitive data exposure. It
serves as a guide for developers to prioritize security efforts.
Answer: Code obfuscation is the practice of making source code difficult to understand.
It is often used to protect intellectual property or make it harder for attackers to reverse
engineer or exploit the application.
Answer:
Answer: Logging and monitoring involve tracking and analyzing system events, user
actions, and network activity to detect suspicious behavior, identify security incidents,
and facilitate response actions.
Answer:
Symmetric encryption uses the same key for both encryption and decryption.
Asymmetric encryption uses a public key for encryption and a private key for
decryption, providing a higher level of security.
Answer: An SDL is a process that integrates security into every phase of software
development, from design to deployment. It includes threat modeling, secure coding
practices, and testing for vulnerabilities.
49. What are security headers, and why are they important?
Answer: Security headers are HTTP headers that provide additional security features to a
web application, such as preventing XSS attacks or enforcing HTTPS. Examples include
Strict-Transport-Security, X-Content-Type-Options, and X-Frame-Options.
Answer: Security audits assess the security of a web application by reviewing code,
configurations, and system architecture for vulnerabilities. Regular audits help identify
and fix security flaws before they are exploited.
Answer: Web development involves the process of building, creating, and maintaining
websites and web applications. It includes both front-end (client-side) and back-end
(server-side) development.
2. What is the difference between front-end and back-end development?
Answer:
Front-end development involves creating the user interface and experience of a web
application (HTML, CSS, JavaScript).
Back-end development involves working with databases, servers, and application logic
(server-side programming, database management).
Answer: Cookies are small pieces of data stored by a browser that are sent to the server
with each request. They are commonly used to maintain user sessions and store user
preferences.
Answer: A session is a way to store information about a user across multiple pages or
requests. Session data is typically stored on the server, while a session ID is stored in the
user's browser (often in cookies).
7. What is a web API?
8. What is REST?
Answer:
GET is used to retrieve data from the server (parameters are passed in the URL).
POST is used to send data to the server (parameters are passed in the body of the
request).
Answer:
Synchronous requests block the execution of the program until the response is
received.
Asynchronous requests allow the program to continue running while waiting for the
response, improving performance and user experience.
Answer: The web request life cycle is the series of steps that a web request goes through
from the time a user makes a request until the response is sent back. It typically involves
receiving the request, routing, controller logic, rendering a view, and returning the
response.
12. What is request routing?
Answer: Request routing is the process of determining which controller and action
should handle a given HTTP request. This is usually based on the URL, method, and
parameters passed with the request.
Answer: A controller handles user requests in a web application. It contains the logic for
processing user input, interacting with the database or services, and returning a response
(usually in the form of a view or data).
Answer: Views are responsible for presenting data to the user. In the MVC (Model-
View-Controller) architecture, views are typically HTML pages that are dynamically
generated with data passed from the controller.
Answer: Routing defines how an application responds to a client request for a specific
URL. It maps a URL pattern to a specific controller and action, which handles the logic
for that request.
18. What is the difference between server-side rendering and client-side rendering?
Answer:
Server-side rendering (SSR) generates HTML on the server and sends it to the client.
Client-side rendering (CSR) sends an empty HTML shell to the client, and JavaScript
running on the client dynamically loads the content.
Answer: HTTP status codes are three-digit numbers sent by the server to indicate the
result of a request. For example, 200 OK means success, 404 Not Found means the
requested resource doesn’t exist, and 500 Internal Server Error indicates a server
issue.
Answer: Caching involves storing copies of resources or data to reduce the load on the
server and speed up response times. Common caching mechanisms include browser
caching, server-side caching, and content delivery networks (CDNs).
Answer: Basic authentication sends the username and password in the HTTP request
header. It’s simple but not secure unless used with HTTPS, as the credentials can easily
be intercepted.
Answer: OAuth is an open standard for authorization that allows third-party applications
to access user data without exposing their credentials. OAuth 2.0 is commonly used to
grant limited access to web resources.
Answer: 2FA is an authentication method that requires two forms of identification before
granting access, such as something you know (password) and something you have (like a
smartphone or security token).
Answer: LDAP is a protocol used to access and manage directory services over a
network. It is commonly used for authentication in enterprise environments to centralize
user management and authentication.
Answer:
Session authentication stores authentication data on the server, and the session ID is
passed to the client (usually in cookies).
Token authentication stores authentication data in the token itself, and the token is
passed along with each request.
Answer: OAuth scopes define the permissions that a third-party application can request
when accessing a user's resources. Each scope represents a specific level of access, such
as read-only or write access to a user's data.
Answer: OpenID Connect is an identity layer built on top of OAuth 2.0 that allows
authentication. It enables single sign-on (SSO) and provides identity verification and
basic profile information about the user.
Answer: RBAC is an authorization model where access to resources is based on the roles
assigned to users. Each role has specific permissions, and users are granted access
according to their role.
34. What is attribute-based access control (ABAC)?
Answer: ABAC is an access control model where access is granted based on attributes
(e.g., user attributes, resource attributes, or environmental conditions) rather than roles.
35. What are the main advantages of JWT over traditional session-based
authentication?
Answer:
Answer: An API key is a unique identifier used to authenticate requests to an API. It’s
usually a string of characters that acts as a security token for API access.
Answer: MFA adds an additional layer of security by requiring users to provide more
than one form of authentication, such as a password, a security token, or biometric
verification.
Answer: Hashing is used to securely store passwords. Instead of storing the password
directly, a hashed version is stored, and only the hashed value is compared during
authentication.
Answer: An access token is a short-lived token that allows a client to access a resource
on behalf of a user. It is issued by the authorization server and must be sent with API
requests.
41. What is the difference between access tokens and refresh tokens?
Answer:
Access tokens are used to access resources and have a short expiration time.
Refresh tokens are used to obtain new access tokens once the current one expires.
Answer: A refresh token is a credential used to obtain a new access token after the
original access token expires. Refresh tokens allow users to remain authenticated without
re-entering credentials.
Answer: An STS is a service that issues security tokens for authentication and
authorization. It is often used in federated identity management to provide access to
different systems or domains.
Answer: Key considerations include using strong encryption (e.g., HTTPS), protecting
against brute-force attacks (e.g., rate limiting), securely storing credentials (e.g., hashing),
and ensuring secure session management.
Answer: The SameSite cookie attribute helps prevent cross-site request forgery (CSRF)
attacks by restricting how cookies are sent with cross-origin requests.
Answer: Token expiration refers to the practice of setting a time limit on how long a
token is valid. After the token expires, the user must re-authenticate or use a refresh token
to obtain a new token.
Answer: Scopes define the level of access that the client application is requesting. Each
scope represents specific permissions, such as access to read or write a user's profile data.