techschool / simplebank
- среда, 10 июля 2024 г. в 00:00:02
Backend master class: build a simple bank service in Go
This repository contains the codes of the Backend Master Class course by TECH SCHOOL.
You can also find it on Udemy at this link.
And don't hesitate to join Tech School's Discord group to chat directly with me and other students.
In this course, you will learn step-by-step how to design, develop and deploy a backend web service from scratch. I believe the best way to learn programming is to build a real application. Therefore, throughout the course, you will learn how to build a backend web service for a simple bank. It will provide APIs for the frontend to do the following things:
The programming language we will use to develop the service is Golang, but the course is not just about coding in Go. You will learn a lot of different topics regarding backend web development. They are presented in 6 sections:
In the 1st section, you will learn deeply about how to design the database, generate codes to talk to the DB in a consistent and reliable way using transactions, understand the DB isolation levels, and how to use it correctly in production. Besides the database, you will also learn how to use docker for local development, how to use Git to manage your codes, and how to use GitHub Action to run unit tests automatically.
In the 2nd section, you will learn how to build a set of RESTful HTTP APIs using Gin - one of the most popular Golang frameworks for building web services. This includes everything from loading app configs, mocking DB for more robust unit tests, handling errors, authenticating users, and securing the APIs with JWT and PASETO access tokens.
In the 3rd section, you will learn how to build your app with Docker and deploy it to a production Kubernetes cluster on AWS. The lectures are very detailed with a step-by-step guide, from how to build a minimal docker image, set up a free-tier AWS account, create a production database, store and retrieve production secrets, create a Kubernetes cluster with EKS, use GitHub Action to automatically build and deploy the image to the EKS cluster, buy a domain name and route the traffics to the service, secure the connection with HTTPS and auto-renew TLS certificate from Let's Encrypt.
In the 4th section, we will discuss several advanced backend topics such as managing user sessions, building gRPC APIs, using gRPC gateway to serve both gRPC and HTTP requests at the same time, embedding Swagger documentation as part of the backend service, partially updating a record using optional parameters, and writing structured logger HTTP middlewares and gRPC interceptors.
Then the 5th section will introduce you to asynchronous processing in Golang using background workers and Redis as its message queue. We'll also learn how to create and send emails to users via Gmail SMTP server. Along the way, we'll learn more about writing unit tests for our gRPC services that might involve mocking multiple dependencies at once.
The final section 6th concludes the course with lectures about how to improve the stability and security of the server. We'll keep updating dependency packages to the latest version, use Cookies to make the refresh token more secure, and learn how to gracefully shut down the server to protect the processing resources. As this part is still a work in progress, we will keep making and uploading new videos about new topics in the future. So please come back here to check them out from time to time.
This course is designed with a lot of details, so that everyone, even with very little programming experience can understand and do it by themselves. I strongly believe that after the course, you would be able to work much more confidently and effectively on your projects.
The service that we’re going to build is a simple bank. It will provide APIs for the frontend to do following things:
brew install golang-migrate
npm install -g dbdocs
dbdocs login
npm install -g @dbml/cli
dbml2sql --version
brew install sqlc
go install github.com/golang/mock/mockgen@v1.6.0
Create the bank-network
make network
Start postgres container:
make postgres
Create simple_bank database:
make createdb
Run db migration up all versions:
make migrateup
Run db migration up 1 version:
make migrateup1
Run db migration down all versions:
make migratedown
Run db migration down 1 version:
make migratedown1
Generate DB documentation:
make db_docs
Access the DB documentation at this address. Password: secret
Generate schema SQL file with DBML:
make db_schema
Generate SQL CRUD with sqlc:
make sqlc
Generate DB mock with gomock:
make mock
Create a new db migration:
make new_migration name=<migration_name>
Run server:
make server
Run test:
make test
Install nginx ingress controller:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.48.1/deploy/static/provider/aws/deploy.yaml
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.4.0/cert-manager.yaml