DynamoDB Point-in-Time Recovery (PITR) - The Ultimate Guide
Written by Chameera Dulanga
Published on November 27th, 2021
Time to 10x your DynamoDB productivity with Dynobase [learn more]
Amazon DynamoDB is a fully managed, cloud-native, NoSQL database service. It guarantees single-digit millisecond latency at any scale and provides multiple backup options to ensure a smooth flow for production-ready applications.
In this article, I will discuss how DynamoDB point-in-time recovery (PITR) works, show different ways to enable it, and compare it with on-demand backups to give you a better understanding.
What is DynamoDB Point in Time Recovery?
Database backups are an essential part of any application. Especially when it comes to cloud databases, backups ensure that no data losses happen in case of regional failovers or disasters.
Amazon DynamoDB provides two options to create database backups: on-demand and continuous. The on-demand approach creates backups only when you request, while the continuous approach creates automatic backups using point-in-time recovery.
If you have enabled point-in-time recovery, you don't need to worry about scheduling on-demand backups and can restore tables to any point in the last 35 days.
Apart from the continuous backups, there are some additional features of point-in-time recovery:
- No performance issues
Enabling point-in-time recovery will not have any impact on performance or API latencies. It won't use any resources from your workload for the backup process and won't need to provide additional throughput. - Table level backups
When you restore a table using point-in-time recovery, the restored table will not be linked to the original database table. Instead, the restored table will appear as a new one, and you will be able to compare the changes and replace data as you need.
Also, when you restore a table, DynamoDB allows configuring several settings of the destination table. So, you can change Global secondary indexes (GSIs), Local secondary indexes (LSIs), Billing mode, Provisioned read and write capacity, and Encryption settings on the restored table. - Time flexibility
Point-in-time recovery allows restoring data up to 35 days (Earliest Restorable DateTime). So you can pick a point to a specific time in hours, minutes, or even seconds to restore. - High Speed
Regardless of the database table size, it will only take a few seconds to restore.
I think now you understand what point-in-time recovery and its features are. Next, I will show you how to enable DynamoDB point-in-time recovery.
How to Enable DynamoDB Point in Time Recovery
Enabling DynamoDB point-in-time recovery through the AWS management console is pretty straightforward.
However, that's not the only way to enable DynamoDB point-in-time recovery. You can use the AWS management console, AWS CLI, DynamoDB API, Terraform, and CloudFormation to enable DynamoDB point-in-time recovery.
Enabling DynamoDB Point-in-Time Recovery using AWS Management Console
To enable DynamoDB point-in-time recovery through the AWS management console, you need to select the DynamoDB table from the tables list and navigate to the Backups tab.
There, you will see the current status of point-in-time recovery and edit it by clicking the Edit button.
Enabling DynamoDB Point in Time Recovery using AWS CLI
If you know your way around with AWS CLI commands, you can enable point-in-time recovery with the following command.
Enabling DynamoDB Point in Time Recovery using CloudFormation
If you are using CloudFormation, you can enable DynamoDB point-in-time recovery by modifying the resources section of the YAML file.
Enabling DynamoDB Point in Time Recovery using Terraform
Also, you can enable DynamoDB point-in-time recovery using Terraform. All you need to do is a small configuration like below:
Note: You can use AWS CloudTrail to log all console and API actions of point-in-time recovery events.
Pricing Model for DynamoDB Point in Time Recovery
Amazon DynamoDB core features are billed based on usage. For example, if you use an on-demand capacity plan, 1.25 USD will be charged per 1 million write request units.
However, this does not include the cost for optional features like point-in-time recovery.
DynamoDB charges for point-in-time recovery based on the size of each table. DynamoDB monitors the size of point-in-time recovery enabled tables throughout the month and decides the backup charges.
For example, if you enable point-in-time recovery for a DynamoDB table in the US East (N. Virginia) region, it will cost you 0.20 USD per GB-month.
Note: DynamoDB point-in-time recovery charges can vary based on the region you select.
Point in Time Recovery vs. On-Demand Backup
Although both on-demand and point-in-time recovery create database backups, there are some differences between these approaches regarding cost, purpose, and availability.
On-demand backups are typically used for ad-hoc backups and are manually triggered. They are useful for creating backups before major changes or for compliance purposes. On the other hand, point-in-time recovery is designed for continuous data protection and allows you to restore your table to any second within the last 35 days, providing a more granular recovery option.
Use Cases for DynamoDB Point-in-Time Recovery
Point-in-time recovery is particularly useful in scenarios where data integrity and availability are critical. For example, in financial applications, where transactions need to be accurately recorded and retrievable, PITR ensures that you can recover to a precise point in time. Similarly, in e-commerce platforms, where inventory and order data are constantly changing, PITR can help recover from accidental data deletions or corruptions.
Frequently Asked Questions
What will happen if I disable DynamoDB point-in-time recovery and re-enable it later?
Disabling and re-enabling point-in-time recovery will reset the start time, which you can recover from that table. So, you will only be able to restore that table to the Latest Restorable DateTime.
What will happen to the backup if I delete a point-in-time recovery enabled DynamoDB table?
If you delete a point-in-time recovery enabled table, DynamoDB will keep a system backup for 35 days. This allows you to restore that table as it was at the point of deletion. Also, there won't be any additional cost for these system backups.
Can I use DynamoDB point-in-time recovery for global tables?
Yes. You can enable point-in-time recovery on each local replica of a global table. When you restore such a table, the backup will be restored to an independent table.
Is it possible to restore DynamoDB tables across regions?
Yes. DynamoDB point-in-time recoveries can be used across regions. You will only be charged for the amount of data you transfer out from the region and restore in the new table.