How Backend Works Without Framework Magic
Recently at an interview, I asked a candidate what happens to active HTTP requests when a Node.js application container restarts in Kubernetes. The person confidently wrote in NestJS for three years, built microservices, but the question stumped them. They never thought about operating system signals, database timeouts, and server shutdown. The framework hid these details under the hood until 500 errors started appearing in production during every deployment.
We are used to building backends from ready-made building blocks. Add a couple of decorators, connect an ORM, press a button, and the API responds to clients. Difficulties begin when ready-made abstractions fail or a service hits limits in memory and CPU.
This problem is covered in repository Backend from First Principles, created by developer DsThakurRawat. The author compiled an engineering reference guide that breaks down server development into basic mechanics.
What's Inside the Repository
The project is divided into 24 topics. They contain notes, architectural diagrams, and code examples in JavaScript. The repository has about three hundred stars on GitHub and a separate documentation site. This is not a bloated commercial course, but open notes from an engineer organizing their own knowledge.
The material is structured sequentially. First come protocols, serialization, and routing, then architectural layers, and closer to the end the author moves on to distributed systems, message brokers, and scaling.
The main idea of the project is simple: when you understand the physics of the process, any new framework can be mastered in a couple of evenings.
Four Topics from the Reference Guide
Instead of a dry summary of the table of contents, let's look at four topics where the author touches on pressing engineering problems.
Graceful Application Shutdown
In typical beginner tutorials, the server is started with app.listen(3000), and that's where the code ends. In production, the server constantly restarts during deployments, due to memory shortages, or during planned node maintenance.
The repository shows in detail how to organize graceful shutdown. When the process receives a SIGTERM signal from the operating system, the application executes a chain of steps:
- stops accepting new incoming HTTP connections;
- gives time for requests already in progress to complete;
- closes connection pools to the database and cache;
- flushes log buffers to disk before exiting.
The author provides a clear example of intercepting system signals in Node.js:
const server = app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
function shutdown(signal) {
console.log(`Received ${signal}. Shutting down gracefully...`);
server.close(() => {
console.log('HTTP server closed');
// Закрываем подключения к базе данных
db.pool.end(() => {
console.log('Database connections closed');
process.exit(0);
});
});
// Принудительное завершение, если запросы зависли
setTimeout(() => {
console.error('Forced shutdown due to timeout');
process.exit(1);
}, 10000);
}
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));
This approach prevents broken transactions and corrupted user data during service updates.
Serialization and CPU Load
Many believe that JSON.stringify() and JSON.parse() work almost for free. At ten requests per second, the difference is indeed imperceptible. When thousands of requests pass through the service, text parsing starts consuming a noticeable share of CPU time.
In the section on serialization, the author breaks down the differences between formats:
- text structures like JSON;
- binary protocols like Protocol Buffers;
- overhead for validation and transformation of incoming schemas;
- the impact of data volume on network throughput.
It clearly shows why engineers choose gRPC and binary formats over plain REST on JSON for internal microservice communication.
Architectural Layers Without Unnecessary Complexity
Developers often mix logic: writing SQL queries directly in controllers or placing parameter validation in the service layer.
The repository covers the classic layered approach:
- controllers receive incoming HTTP requests and form responses;
- services implement business rules and application logic;
- repositories are responsible for database interaction;
- middlewares check authorization, log metrics, and enrich the request context.
Clear layer separation helps test business logic in isolation without spinning up a database and making real network calls.
Asynchronous Tasks and Queues
If a user needs to generate a complex PDF report or process video, doing this inside an HTTP request is not an option. The client will get a timeout error, and the service worker thread will be blocked.
The guide covers the background task workflow pattern:
- saving the job to a message broker queue;
- returning a 202 Accepted response with a task identifier to the client;
- asynchronous execution by workers in a separate pool;
- retry strategies for failures and sending problematic messages to Dead Letter Queue.
Drawbacks and Rough Edges
The project is relatively young, so it has limitations.
Almost all code is written in JavaScript. If your main stack is Go, Java, Rust, or C#, you'll need to mentally adapt the examples for typing and your platform's specifics. The author explicitly states in the README that they welcome community help with examples in other languages.
Some topics currently read more like brief theses than comprehensive articles. It would be nice to see more real incident analyses and performance benchmarks with graphs.
Who Will Benefit from This Repository
This project can be used in four practical situations:
- Junior developers who want to understand network protocols, OS signals, and database structure.
- Engineers preparing for System Design sections and technical interviews.
- Developers transitioning from monolithic architecture to distributed services.
- Tech leads for creating development plans or onboarding new team members.
Final Thoughts
DsThakurRawat's reference guide helps you see the backend as a comprehensible set of engineering principles, not library magic. You don't have to study it cover to cover.
Bookmark the repository and open the relevant section when designing architecture, configuring cache in Redis, or preparing a microservice for deployment to Kubernetes.
Proyectos relacionados