Backend Flashcards
(19 cards)
What is a path parameter in a backend API?
A path parameter is a variable part of a URL that is used to identify a specific resource within a RESTful API.
True or False: Path parameters are always optional in API endpoints.
False
Fill in the blank: In a URL like ‘/users/{userId}’, ‘{userId}’ is an example of a __________.
path parameter
Which of the following is a correct way to define a path parameter in a RESTful API? (A) /products/{productId} (B) /products?productId={productId} (C) /products/productId/{productId}
A
What is the primary purpose of using path parameters in API design?
To uniquely identify resources and provide a clear structure for accessing them.
What type of database is Redis?
Redis is an in-memory key-value store.
True or False: Redis supports data persistence.
True.
Fill in the blank: Redis is often used for ___.
caching.
What data structure does Redis primarily use?
Key-value pairs.
Which command is used to set a value for a key in Redis?
SET.
What is the maximum size of a Redis string?
512 megabytes.
Which of the following is NOT a data type supported by Redis? a) List b) Set c) Table
c) Table.
How does Redis achieve high performance?
By storing data in memory.
True or False: Redis supports transactions.
True.
For what “Redis” stands?
Remote Dictionary Server
What are microservices?
Microservices are small, independent applications that perform specific tasks, allowing for flexible deployment and scaling. This modular approach to software design loosens the coupling between components, enhancing flexibility and manageability throughout development.
What is the N+1 query problem?
It’s a situation where an application executes 1 query to fetch a list of records (N records), and then for each of those N records executes a separate query—resulting in N+1 queries total. This causes many database calls and significantly reduces performance.
How can you recognize the N+1 query problem in your code? (3)
You see a loop where a database query is executed each iteration.
SQL logs show many similar SELECT queries with different IDs.
The app runs fine with a small number of records but slows drastically as the number increases.
Profiling tools show query count growing linearly with the number of objects.
How can you solve the N+1 query problem?
Use a single query with JOINs to fetch data all at once. Then, organize associations in application memory (e.g., group comments by post_id).
SELECT posts.id, posts.title, comments.body
FROM posts
LEFT JOIN comments ON comments.post_id = posts.id;
grouped = group_by(comments, key=lambda c: c.post_id)
for post in posts:
post.comments = grouped.get(post.id, [])