10: Difference between Clustered and Non-Clustered Index
Answer:
A clustered index determines the physical order of data in the table. It is faster but requires less memory and only allows one per table. A non-clustered index, on the other hand, does not dictate the physical order of the data and can exist multiple times per table. It takes up more memory as it stores both values and pointers to the data, whereas a clustered index only stores pointers to blocks of data.
- Speed: Clustered index is faster than non-clustered index.
- Memory Usage: Clustered index uses less memory.
- Storage Structure: Clustered index stores pointers to blocks, while non-clustered stores both values and pointers.
- Size: Clustered indexes are larger, while non-clustered ones are comparatively smaller.
- Default for Primary Keys: Primary keys use clustered indexes by default.
Q.11: What is a Web Server?
Answer:
A web server is either a software application or a hardware device that serves web pages to users’ browsers. It processes requests and delivers content like HTML files, images, and other resources. Examples include Apache HTTP Server, Nginx, Microsoft IIS, and LiteSpeed Web Server.
- Functions: Handles client requests, stores and processes data, delivers web content.
- Popular Web Servers: Apache, Nginx, IIS.
Q.12: What is SQL Injection? How Can We Prevent It?
Answer:
SQL injection occurs when an attacker inserts or manipulates SQL queries, exploiting vulnerable code to access or manipulate database information. Preventive measures include using parameterized queries, prepared statements, and input validation.
- Prevention Techniques:
- Use of parameterized queries.
- Prepared statements in SQL.
- Regular input validation and sanitization.
- Use of parameterized queries.
Q.13: How Do You Create a Simple Server in Node.js That Returns “Hello World”?
Answer:
To create a simple HTTP server in Node.js, use the http module and listen to requests, returning “Hello World”. Here’s an example:
javascript
const http = require(“http”);
http.createServer((req, res) => {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Hello World\n’);
}).listen(3000); // Listen on port 3000
This script will create a server that listens on port 3000 and responds with “Hello World”.
Q.14: What is MVC Architecture?
Answer:
MVC (Model-View-Controller) is an architectural pattern that separates an application into three components:
- Model: Manages data and logic.
- View: Displays the data (UI).
- Controller: Handles the input, processes it, and updates the model and view.
Benefits of MVC:
- Separation of Concerns: Allows independent design of components.
- Reusability: Views and controllers can reuse UI components.
- Flexibility: Changes in UI can be achieved without affecting business logic.
Q.15: What is API Rate Limiting? Give a Few Rate Limiting Algorithms
Answer:
API rate limiting is used to control how many requests a client can make to an API within a certain timeframe. It helps prevent abuse and ensures fair usage. Common rate-limiting algorithms include:
- Token Bucket Algorithm: Tokens are provided at a fixed rate, and each request consumes one token.
- Leaky Bucket Algorithm: Requests are added to a bucket at a fixed rate, and the bucket has a maximum capacity.
- Fixed Window Counter: Counts requests within a fixed window of time.
- Sliding Window Log: Maintains a log of request timestamps.
- Adaptive Rate Limiting: Adjusts the rate limit dynamically based on traffic.
Q.16: How Do You Select Between REST and SOAP for Web Services?
Answer:
When deciding between SOAP and REST, consider the following:
- Nature of Data: SOAP is better for exposing business logic, while REST is more suited for data exposure.
- Contract Requirement: SOAP requires a strict contract (WSDL), whereas REST does not.
- Security: SOAP is preferred for high-security transactions; REST depends on the underlying implementation.
- Transaction Support: SOAP supports advanced transaction features, while REST has limited support.
- Bandwidth Usage: SOAP has high bandwidth due to XML overhead, while REST is more lightweight.
Q.17: What is the DRY Principle in Software Development?
Answer:
The DRY (Don’t Repeat Yourself) principle in software development emphasizes reducing code duplication. This principle suggests that each piece of logic should only exist in one place. It improves maintainability, reduces the risk of errors, and ensures consistency.
Example:
Without DRY:
python
def validate_email(email):
if not email or “@” not in email:
return False
return True
With DRY:
python
def validate_email(email):
if not email or “@” not in email:
return False
return True
def update_profile(user, email):
if not validate_email(email):
raise ValueError(“Invalid email address”)
user.email = email
Q.18: What is the Difference Between First-Party and Third-Party Cookies?
Answer:
Cookies are small files stored on your computer by websites. Here’s the difference:
- First-Party Cookies:
- Created by the website you’re visiting.
- Used to remember user preferences or login information.
- Accessible only by the website that created them.
- Created by the website you’re visiting.
- Third-Party Cookies:
- Created by domains other than the one you’re visiting.
- Used for tracking user behavior across websites for targeted advertising.
- Accessible by any website using the same third-party code.
- Created by domains other than the one you’re visiting.
👉The Next 7 Questions-3: BACKEND