Which language should you learn for backend? The short answer: pick exactly one of the three popular stacks in Vietnam and learn it deeply, instead of learning all three. Node.js with TypeScript (NestJS or Express) suits people who already know JavaScript and want to join startups or e-commerce; Java Spring Boot suits people aiming for banks, fintech or Japanese outsourcing companies; Python FastAPI suits people drawn to data and AI. What employers actually check in a junior is not the language name, but whether you organise a project into controller, service and repository layers and manage configuration with environment variables properly. This lesson helps you choose a stack, then build a clean project skeleton through a worked example.
By the end of this lesson, you will be able to:
- Tell a language, a runtime and a framework apart; compare Node.js TypeScript, Java Spring Boot and Python FastAPI on 8 criteria.
- Choose one main stack using 3 questions and 30 real job ads in your area.
- Organise an API into 3 layers, controller, service and repository, and explain which logic belongs where.
- Configure an app with
.envand.env.example, check for missing variables at startup and keep secrets off GitHub. - Plan 12 weeks and 120 hours to finish this step with a small working project.
Learning backend development? Choosing one main language and framework is step 2 of the 9-step roadmap, after programming basics, Linux and Git, and before REST APIs and databases. See the backend developer roadmap to see where this lesson fits.
Why choose only one main language at this step?
In step 1 you built the foundations: data structures, the Linux command line, Git and the habit of reading logs (see How to start learning backend). Step 2 turns those foundations into the ability to write a structured backend application, and that requires going deep into one ecosystem.
Spreading yourself thin is the most common mistake
Many beginners watch "Node.js in 1 hour", then "Spring Boot in 2 hours", then switch to Go because they heard it pays well. Three months later they can print "Hello world" in four languages but still cannot write an API that validates input and talks to a database on their own. Junior hiring managers want someone productive in one stack, not someone who has dabbled in every stack.
How do a language, a runtime and a framework differ?
These three ideas get mixed up when reading job ads:
- Language is the syntax and rules for writing code: TypeScript, Java, Python.
- Runtime is the environment that executes code: Node.js runs JavaScript (TypeScript is compiled to JavaScript before running), the JVM runs Java, and the Python interpreter runs Python.
- Framework is a ready-made skeleton for organising code, routing URLs, validating data and wiring libraries: Express, NestJS, Spring Boot, FastAPI.
So "learning Node.js" really means learning TypeScript, how Node.js runs asynchronous code and a framework such as NestJS: choosing once means choosing the whole package. The layered structure in this lesson exists in all three frameworks, so switching stacks later is mostly a matter of new syntax and libraries.
Node.js TypeScript vs Java Spring Boot vs Python FastAPI
The table compares the three options from a Vietnamese beginner's point of view. The "who hires" row is a general trend for you to verify yourself, not a statistic.
| Criterion | Node.js + TypeScript | Java Spring Boot | Python FastAPI |
|---|---|---|---|
| Typing | Static via TypeScript (compiled to JavaScript) | Static, strict | Dynamic, with type hints for checking |
| Common frameworks | Express (minimal), NestJS (structured) | Spring Boot | FastAPI, also Django, Flask |
| Package management | npm, pnpm | Maven, Gradle | pip, Poetry, uv |
| Typical ORM | Prisma, TypeORM | Spring Data JPA (Hibernate) | SQLAlchemy |
| Who hires | Startups, e-commerce, web and app products | Banks, fintech, Japanese outsourcing, large systems | Data and AI companies, internal tools |
| Starting difficulty | Low if you know JavaScript | Higher: more concepts and configuration | Low, readable syntax |
| Study machine | 8 GB RAM is fine | IDE and JVM are more comfortable with 16 GB RAM | 8 GB RAM is fine |
| Auto-generated API docs | Official Swagger package for NestJS | springdoc library | Built-in /docs page |
Node.js with TypeScript: Express or NestJS?
Node.js uses an event loop: one main thread handles many requests that are waiting on the database or network without blocking. Sharing a language with the frontend is a strength; plain JavaScript's loose typing is a weakness, so use TypeScript with strict mode on from day one.
Express is minimal and lets you decide the folder layout, so beginners easily end up with one 800-line file. NestJS (which runs on Express underneath by default) pushes you to split code into modules, controllers and services and has dependency injection built in, so the project stays tidy as it grows. Practical advice: spend 1-2 weeks with Express to understand how a request passes through middleware, then switch to NestJS for your main project.
Java Spring Boot: strict, with many jobs at large companies
Spring Boot is the most popular Java framework for backend work, using annotations such as @RestController, @Service and @Repository to mark each layer. Java makes you declare types explicitly, so you write more slowly at first but errors are caught early at compile time. Spring Boot 3 requires Java 17 or later, so install an LTS JDK such as 17 or 21 instead of the Java 8 used in older tutorials.
Python FastAPI: quick to start, close to data and AI
FastAPI uses Python type hints and the Pydantic library to validate input, and generates OpenAPI documentation at the /docs path automatically. Python's readable syntax lets beginners write a first API after a few sessions. FastAPI does not enforce a folder structure, so you must split the layers yourself following the pattern below. If you build backends for products with AI features, Python is the natural choice.
How to choose your stack in one evening
Stop reading "which language is best" debates. Answer three questions, then check them against real job ads; it takes about 2-3 hours.
Three deciding questions
- Which language can you already write? If you have done JavaScript on the frontend, Node.js TypeScript saves you weeks. If you learned Java at school, go with Spring Boot.
- What kind of company do you want to work for? Banks, insurers and Japanese companies tend to prefer Java. Startups, e-commerce platforms and agencies often use Node.js. Data and AI teams favour Python.
- How powerful is your machine? As a rule of thumb, a Java IDE with Spring and a database is more comfortable with 16 GB of RAM; Node.js and Python are lighter.
Read 30 job ads instead of reading debates
Go to ITviec, TopDev or LinkedIn and filter for "junior backend" or "fresher backend" in the city where you want to work. Open the 30 most recent ads and note in a spreadsheet: required language, framework, database and experience level. Count which stack appears most often among the companies you like. A number you counted yourself in your own area is more reliable than any general ranking.
On income, the NAMBIN roadmap estimates freshers at about 9-13 million VND per month (~USD 350-500) and junior to mid-level backend developers at about 18-40 million VND (2026 reference, varies by region, language and company, in Vietnam).
Layered project structure: controller, service, repository
A layered structure splits code by responsibility, so each file does one kind of job. When an API has 30 endpoints, this split decides whether you find a bug in 5 minutes or 2 hours. Junior interviews often ask: "Which layer should check for a duplicate phone number?"
Photo: Bdecarne / Wikimedia Commons, CC BY-SA 4.0
Each layer does one job
Picture a request travelling from the outside in and back out again, like the sketch on the whiteboard in Figure 1:
- Controller (request layer): reads the URL, parameters and body; calls the right service method; returns the response. It holds no business rules and no queries.
- Service (business layer): holds the rules of the problem, for example "phone numbers must be unique" or "a delivered order cannot be cancelled". This is where unit tests pay off most.
- Repository (data access layer): reads and writes the database or other storage. The service does not need to know whether data lives in PostgreSQL, MongoDB or temporarily in memory.
Besides the three main layers there are DTOs (Data Transfer Objects, describing the data going in and out of the API) and entities/models (describing one record in the database).
A sample folder tree
Split folders by feature (module) first, then by layer inside each module. That way opening one folder shows everything about that feature, like the project tree on the left of the screen in Figure 2. A NestJS example:
src/
main.ts
app.module.ts
config/
env.validation.ts
customers/
customers.module.ts
customers.controller.ts
customers.service.ts
customers.repository.ts
dto/create-customer.dto.ts
customer.entity.ts
customers.service.spec.ts
.env.example
.gitignore
Spring Boot: a customer package containing CustomerController, CustomerService, CustomerRepository. FastAPI: an app/customers/ folder with router.py, service.py, repository.py.
Photo: The other Kiwix guy / Wikimedia Commons, CC BY-SA 4.0
Dependency injection for beginners
Dependency injection (DI) means a class does not create the objects it needs; it declares them in its constructor and the framework passes them in. A controller that needs a service declares the service in its constructor; a service that needs a repository does the same. That way, when testing the service, you pass in a fake repository without changing any code. NestJS and Spring Boot do DI automatically; FastAPI uses Depends. Dependencies flow in one direction only: controller calls service, service calls repository, never the other way round.
Worked example: a customer book API for a repair shop
Mr. Tam runs a motorbike repair shop and wants an API that keeps a customer book so he can text reminders for oil changes. The first requirement: add a customer with a name and phone number; the number must be normalised (remove spaces, turn "+84", Vietnam's country code, into a leading "0") and must not be duplicated. We build it in NestJS with in-memory storage; at the database step you only replace the repository.
Step 1: the controller only receives and forwards
@Controller('customers')
export class CustomersController {
constructor(private readonly customers: CustomersService) {}
@Post()
create(@Body() dto: CreateCustomerDto) {
return this.customers.create(dto);
}
}
The controller knows nothing about the duplicate rule; it only receives the body and passes it to the service.
Step 2: the service holds the business rule
@Injectable()
export class CustomersService {
constructor(private readonly repo: CustomersRepository) {}
async create(dto: CreateCustomerDto) {
const phone = normalizePhone(dto.phone);
const existed = await this.repo.findByPhone(phone);
if (existed) {
throw new ConflictException('Phone number is already in the book');
}
return this.repo.insert({ name: dto.name.trim(), phone });
}
}
function normalizePhone(raw: string) {
const digits = raw.replace(/\s+/g, '');
return digits.startsWith('+84') ? '0' + digits.slice(3) : digits;
}
Step 3: the repository handles storage
@Injectable()
export class CustomersRepository {
private rows: Customer[] = [];
private nextId = 1;
async findByPhone(phone: string) {
return this.rows.find((c) => c.phone === phone) ?? null;
}
async insert(data: Omit<Customer, 'id'>) {
const row = { id: this.nextId++, ...data };
this.rows.push(row);
return row;
}
}
The methods are async even though storage is in memory, because database reads will be asynchronous later; the service will not need any changes when you switch.
Step 4: send three requests and check the results
Send three POST /customers requests in order with curl or Postman. The expected results are in the table:
| Request | Body sent | Number after normalising | What the service does | Result |
|---|---|---|---|---|
| 1 | Ms. Lan, "0901 234 567" | 0901234567 | Not found, saved with id 1 | 201, book has 1 customer |
| 2 | Mr. Hung, "+84901234567" | 0901234567 | Already exists, throws ConflictException | 409, book still has 1 customer |
| 3 | Ms. Mai, "0912345678" | 0912345678 | Not found, saved with id 2 | 201, book has 2 customers |
After 3 requests there are 2 successful saves and 1 rejection, so the book holds exactly 2 customers with ids 1 and 2. Request 2 shows the benefit of normalising in the service: two spellings of the same number are still caught as a duplicate. Status codes 201 and 409 are covered in depth at the REST API step.
Managing environment variables and configuration
Environment variables are configuration values that live outside the code and are supplied by the operating system or deployment platform when the app runs. The same code runs on your laptop, on a staging server and in production with different databases and API keys. The principle "configuration lives in the environment, not in the code" comes from The Twelve-Factor App guidelines and is followed by most teams.
Why not hard-code passwords?
If you write a connection string or API key into the code, anyone who can read the repo has the password, changing servers means editing code and rebuilding, and a colleague's machine might connect to the production database by mistake.
.env, .env.example and .gitignore
On your machine, real values go into a .env file, and that file must be listed in .gitignore. The .env.example file is committed and lists every variable name with dummy values so others know what to set:
# .env.example (commit this file, do NOT commit .env)
PORT=3000
DATABASE_URL=postgres://user:change-me@localhost:5432/customer_book
SMS_API_KEY=put-the-real-key-in-env
LOG_LEVEL=debug
On servers, real values are set in the deployment platform's configuration or a secret manager; you will do this at the Docker and deployment step.
Read and check configuration at startup
The app should stop immediately when a required variable is missing, instead of starting and then failing while customers are using it:
- NestJS: the
@nestjs/configpackage reads.env, with a check function inenv.validation.ts. - Spring Boot: declare values in
application.yml, for examplespring.datasource.url: ${DATABASE_URL}; split configuration bydevandprodprofiles. - FastAPI:
pydantic-settingswith a typed settings class; a missing required variable raises an error at startup.
// Minimal check in NestJS or Express
const required = ['DATABASE_URL', 'SMS_API_KEY'];
for (const key of required) {
if (!process.env[key]) {
throw new Error(`Missing environment variable ${key}`);
}
}
One codebase, many environments
At a company, the same build usually moves through dev, staging and then production, each running on its own servers like the racks in Figure 3. Only the variable values change: database address, log level, test or live payment keys. Having to edit code every time you switch environments is a sign that configuration is hard-coded.
Photo: meta:User:Midom / Wikimedia Commons, CC BY 2.0
Security warning: if you accidentally commit a .env file or an API key to GitHub, treat that key as leaked. Deleting the file in a later commit is not enough, because Git history keeps it and bots scan public repos for keys. First revoke and issue new credentials (change the database password, rotate the API key), tell whoever is responsible, and only then clean up the history.
A 12-week, 120-hour plan for this step
For someone studying about 10 hours a week in the evenings, step 2 usually takes about 12 weeks. The table splits the time by concrete outputs; the rows add up to 30 + 20 + 20 + 15 + 35 = 120 hours.
| Weeks | Content | Hours | Output to check yourself |
|---|---|---|---|
| 1-3 | Main language in more depth: types, classes, error handling, async | 30 | 15 small exercises with strict type checking on |
| 4-5 | Framework basics: routes, request bodies, middleware | 20 | A "hello" API with 3 working routes |
| 6-7 | Controller, service and repository layers, DI, unit tests for services | 20 | The customer book example with 3 passing tests |
| 8-9 | Configuration with environment variables, levelled logging | 15 | A missing variable stops the app with a clear message |
| 10-12 | Small project: 2 modules, 6-8 endpoints, a README on how to run it | 35 | Someone else can clone and run it within 15 minutes |
Common mistakes when choosing a stack and setting up a project
When you are stuck for more than an hour, ask someone or get your study group to read the error with you, like the group gathered around one laptop in Figure 4.
Photo: Hay Kranen / Wikimedia Commons, CC BY 4.0
The "fat" controller
Sign: a controller file hundreds of lines long that validates data, writes queries and calculates prices. Cause: following short tutorials that put everything in one place. Fix: move business rules into the service and queries into the repository; each controller method should be a few lines.
The service talks to the database directly
Sign: SQL or ORM calls scattered through the service. Cause: an extra repository feels unnecessary. Fix: put all data access in the repository, so testing the service only needs a fake repository.
Committing .env to GitHub
Sign: a public repo contains a .env file with real passwords. Cause: creating .gitignore after the first commit. Fix: revoke the keys as in the warning above, add .env to .gitignore and run git rm --cached .env so Git stops tracking the file.
Switching frameworks constantly
Sign: starting over with a new framework every month, with no project finished. Cause: fear of choosing wrong. Fix: commit to one stack for 12 weeks, write down the decision and reasons in a note, and only revisit it after finishing the project.
Frequently asked questions
Which backend language should a complete beginner choose?
If you know no language yet, choose Node.js TypeScript or Python FastAPI for quick results that keep you motivated. If you are sure you want to work at a bank or a Japanese outsourcing company, start with Java Spring Boot even though the first stretch is slower.
Can you get a backend job with Python FastAPI?
Yes, especially at data and AI companies and on internal products. The number of pure FastAPI junior openings may be lower than for Java or Node.js depending on the area, so count the job ads before deciding.
Is the controller, service, repository pattern mandatory?
It is not a law, but it is a safe default for beginners and most teams. Very small projects may merge layers; large systems may add layers such as domain or use cases. Understanding these three layers first makes more complex architectures easier to read later.
Practice exercises and self-assessment
- Read 30 junior backend job ads in your area, record the language, framework and database in a table, and write 5 lines on why you chose your stack.
- Rebuild the customer book example in your chosen stack with exactly 3 layers, and add an endpoint that lists customers.
- Write 3 unit tests for the service: a successful add, a duplicate in "+84" form, and a name with extra spaces being trimmed.
- Create
.env.example, add.envto.gitignoreand add a startup check for required variables.
Self-assessment criteria
- Pass: the controller contains no queries or business rules; not yet: the duplicate check is still in the controller.
- Pass: the 3 requests in the example table return 201, 409, 201 and the book has 2 customers; not yet: the second request still saves.
- Pass: removing a variable from
.envstops the app immediately with a message naming the variable; not yet: it starts and fails only when an API is called. - Pass: the Git history contains no
.envfile or real keys; not yet: it does, even if deleted in a later commit.
Once your small project runs with clean layers and clean configuration, move on to the next step of the roadmap: HTTP, REST APIs & Swagger docs. There you will learn to choose methods and status codes, paginate, return consistent errors and write OpenAPI documentation for this very customer book API; read What is a REST API beforehand to get familiar.
Keep learning backend development: after language and framework come REST APIs, databases, security, caching and queues, Docker and deployment, and a complete API project. See the backend developer roadmap.


