Build a Goodreads Clone with Spring Boot and Astra DB — Part 1
Author: Pieter Humphrey
Want to learn how to build a quick and simple Spring Boot application that is highly available, easily scalable, and can handle millions and millions of data records? This video tutorial and companion blog series will guide you through building a Spring Boot book tracking application end-to-end, and then connecting it to the NoSQL cloud database — DataStax Astra DB.
You may already know how to build a simple application with Spring Boot, but do you know how to make that same app scale, have high availability, and handle millions of views? The new Code With Me — Better Reads series from Java Brains, focuses on building a clone of the popular website, Goodreads.com which can handle large amounts of data.
You’ll be building a full-stack Spring Boot application, backed by the cloud-native Astra DB, built on a serverless implementation of Apache Cassandra. The intention is to build an app that can store a catalog of every book published in the world! For this, we’re going to need the power of Astra DB.
In this first installment of the series, you’ll start by designing the UX.
The app you will build: BetterReads
If you have ever used Goodreads.com, then you will find the application you will be building with this tutorial is very similar: a book tracker. Though our app will be slightly simplified functionality-wise, we still want to be able to do all this at scale.
First, let’s walk through the features of the app that we’re going to build.
- SSO login using GitHub
- Search via book title or author
- Landing pages for book includes title, author, description, cover photo
- A personal dashboard
- Ability to track a particular book, set reading start/end dates, and ratings. Currently reading books show up at the top, and finished books are ordered by the finish date
The BetterReads app is designed to be fast—even if we were to have literally every book ever published saved in our database, we expect pages to load quickly. With the architecture that you are going to build out, individual pages will render super fast, despite the huge amount of data we are serving. You will be able to scale the app to our needs, no matter if there are ten users or hundreds of thousands of users.
The technologies we will be using are: Astra DB, Spring Boot, Spring Security, ThymeLeaf, and Spring Data for Apache Cassandra®.
What is Astra DB?
Astra DB is the cloud database-as-a-service built on the NoSQL data engine: Cassandra, that powers global enterprises like Netflix and Instagram. Cassandra is known for its high availability, linear scalability, and unparalleled horsepower even at petabytes of data.
Astra DB configures and manages Cassandra for you so you can focus on building and deploying cloud-native applications within a matter of minutes. It’s also completely free up to 80GB storage and/or 20 million monthly operations. Even beyond this, Astra DB is completely serverless, reducing your costs by allowing you to run Cassandra clusters only when needed, using intelligent autoscaling.
What is Spring Security?
Spring Security is a powerful and highly customizable authentication and access-control framework that focuses on providing both authentication and authorization to Java applications. It is also the de-facto standard for securing Spring-based applications.
Like all Spring projects, the real power of Spring Security is found in how easily it can be extended to meet custom requirements.
What is ThymeLeaf?
With modules for Spring Framework and a host of integrations with various tools, ThymeLeaf is ideal for modern-day HTML5 JVM web development.
What is Spring Data for Apache Cassandra?
The Spring Data for Apache Cassandra project applies core Spring concepts to the development of solutions when using Cassandra.
Spring Data Cassandra wraps the DataStax Java Driver and is one way of connecting your Java application code and your Cassandra database. It allows you to form records from POJOs, and then write queries by simply typing a valid method name.
A good alternative to connect a Spring Boot project to Cassandra is to use the Stargate project, which offers app-to-database connectivity via REST, GraphQL, gRPC, and a schemaless JSON document API.
The requirements for this tutorial are:
- JDK and some IDE installed (IntelliJ, VSCode, Eclipse, etc.)
- A free Astra DB account
Designing the UX
It is very important to do UX design first, as it will give you an idea of the overall flow of the app, what kind of data we will need, and how we need to optimize our database for common usage patterns. Knowing how users will query the data is particularly important for a denormalized database, such as Cassandra, so we can structure our database accordingly. We know we want our app to do the following:
- Host the metadata of “All the Books in the World”
- Allow users to browse books by name and author
- Allow users to mark a book as “Read” or “Want to Read”
- Dashboard of books you have read or want to read
- Ability to rate books
The data Source we will be using is OpenLibrary. Due to the enormous volume of data provided by the OpenLibrary’s Data dump, you will be using a subset of this data later in a later blog post for testing your application.
These are the key pages, or UX elements that we will need for our application:
- The Book Page: You are going to provide one page for every book in the database. This page will include basic information about the book, such as the cover image, title, description, and author. There is an additional form included for a logged-in user. If they have read the book, they can provide a start and end date, and a rating for the book. For status, they can say whether they are currently reading or finished reading the book. This page needs to be performant, all this book information needs to be able to load as quickly as possible.
- The Author Page: If a user clicks on an author’s name from the Book Page, they will be brought to the Author page. This page will have an image of the author, if available, and the books the author has written (with the most recently written showing up first). There will be a page for every author in our database.
- The Search Page: Users can search for a book. There will be a text box and a search input button. A user can enter a book title, and once they search for a book, they should get all the books that match that particular search criteria.
- Home Page (no-login): Since some functionality of the app requires a user session (ex. marking a book as read), we need a login page. The Home page will have an OAuth login and a search text box. We don’t want to restrict the usage of the app to users who have logged in, but if they want to mark a book as “read”, for instance, they need to log in.
- Home Page (Logged in): If the user is logged in, the home page will be a view of their dashboard, along with a list of the most recent books they have read, in reverse chronological order. Books currently being read will be listed on top.
This has been a basic overview of the design of the UX. In the next blog post in this series, we will begin preparing for development as we explore the overall system design and architecture of the Better Reads app. We will design our application and database to work efficiently with this huge amount of book metadata. Check out the Github repository with the full code for this project.
- Code With Me — Better Reads
- Astra DB: Multi-cloud DBaaS built on Apache Cassandra
- Create an Astra DB account
- Apache Cassandra
- Java Brains on YouTube
- Stargate Project
- BetterReads project — Github
- DataStax Tech Blog
- DataStax YouTube channel
- Documentation: Create an Astra DB database
- DataStax Twitter for Developers
- DataStax Community