Book Image

Rust Web Programming - Second Edition

By : Maxwell Flitton
Book Image

Rust Web Programming - Second Edition

By: Maxwell Flitton

Overview of this book

Are safety and high performance a big concern for you while developing web applications? With this practical Rust book, you’ll discover how you can implement Rust on the web to achieve the desired performance and security as you learn techniques and tooling to build fully operational web apps. In this second edition, you’ll get hands-on with implementing emerging Rust web frameworks, including Actix, Rocket, and Hyper. It also features HTTPS configuration on AWS when deploying a web application and introduces you to Terraform for automating the building of web infrastructure on AWS. What’s more, this edition also covers advanced async topics. Built on the Tokio async runtime, this explores TCP and framing, implementing async systems with the actor framework, and queuing tasks on Redis to be consumed by a number of worker nodes. Finally, you’ll go over best practices for packaging Rust servers in distroless Rust Docker images with database drivers, so your servers are a total size of 50Mb each. By the end of this book, you’ll have confidence in your skills to build robust, functional, and scalable web applications from scratch.
Table of Contents (27 chapters)
Free Chapter
1
Part 1:Getting Started with Rust Web Development
4
Part 2:Processing Data and Managing Displays
8
Part 3:Data Persistence
12
Part 4:Testing and Deployment
16
Part 5:Making Our Projects Flexible
19
Part 6:Exploring Protocol Programming and Async Concepts with Low-Level Network Applications

Breaking down our project

We are building a simulation platform where users can log in and interact with fake simulated people via chatbots to see what they say to the fake people. We want to see what the users say to the fake people at the end of the simulation session. The problem is that there are a lot of messages being sent to a fake person in a short amount of time. If we hit the database every time a message is sent, then we will put our database under a lot of strain. Let us say that a user asks a question every 20 seconds; this means we will be hitting the database 6 times per minute as there is a question and an answer per interaction. If we have 800 users running a session at the same time, then we can have up to 4,800 hits a minute. This can put a strain on the database. To reduce the strain on the database, we can build a server in Hyper that caches the chats and periodically sends multiple questions and answers to the database. Before moving forward, this is a chance...