Skip to content

17 Staybooking Backend Summary

Staybooking

Goal

  • Summary of StayBooking backend.

Backend Summary

What’s the difference between Spring and SprintBoot?

SpringBoot provides an easier way to start and build a Spring-based project. It provides starter dependencies to simplify the Maven configuration file, integrates a Tomcat server so I don’t need to prepare the server myself, and also provides the external application.properties file so that information like DB address, GCS bucket, Token secret don’t need to be hard-coded in the java files.

How do you use Spring MVC?

I used Spring MVC to create my REST APIs on the backend. The general idea is to split the backend code into different packages like controller, service, repository, and model, and mark each part with the corresponding annotation so that the code becomes cleaner and much more decoupled from each other.

How do you use GCS?

I use GCS to store all photos uploaded by users. The corresponding link of each photo is stored in MySQL.

Why not store media files in the database directly?

Because a database is not good for storing a binary blob (like a media file). First, it’ll be much slower to store media files than to store them in a file system directly. Second, media files will increase the size of the database a lot which will be hard to maintain. GCS is good for media files because it behaves like a file system, with high availability, durability, and is less expensive. also provides CDN service to serve files in edge servers to reduce loading latency.

How could you improve the user experience when loading large image files?

I can update the storage class for my GCS objects to have replicas in more regions. I can pick the regions based on where the user traffic comes from so that GCS can behave like a CDN service to serve files in edge servers to reduce loading latency.

How do you use Elasticsearch?

I use Elasticsearch as a search index to support geo-based stay search. The Elasticsearch server is hosted on the GCE VM.

How do you implement the authentication functions in your project?

I use JSON Web Token for server authentication.

What’s the advantage of a token over a session?

Stateless and Scalable - Stateless: The back-end does not need to keep a record of tokens. - Scalable: The back-end does not need extra DB spaces when creating Token for new users.