Cloud storage services

Giorgio Boa
FullStack Developer @ Qarik
Microsoft MVP
In this application you see in the image below you give users the opportunity to save a video to post it and link it to their user profile.
This is where the problem arises:
Where do you save these videos so that they are available globally on any user device?
# Persistence videos in the database 🙅
To save information and have a single source of truth you have always been used to thinking about the database.
You save the data there and that's fine. In this case, however, it is not the correct choice for various reasons:
- Performance: Storing large videos in the database can impact performance, especially for read and write operations.
- Scalability: Databases may struggle to handle massive amounts of data, leading to performance bottlenecks.
- Storage cost: Storing videos in the database can be really expensive.
- Database size: Videos can significantly increase database size, leading to higher storage costs and potential performance issues.
# Cloud Storage Services 🚀
Storing images on Cloud Storage Services instead of a database offers several benefits:
Performance and Scalability:
- Faster Retrieval: Cloud Storage Services are optimized for storing and retrieving large files like videos/images.
This results in significantly faster loading times for users compared to retrieving them from a database.
- Scalability: Cloud Storage Services are a highly scalable services, easily handling the storage and retrieval needs for massive datasets.
Databases, particularly relational ones like PostgreSQL, are not optimized for handling large binary data like images/videos.
- Reduced Database Load: By offloading image/video storage to Cloud Storage Services, you reduce the load on your database, leading to improved overall performance and efficiency.
- Pay-as-you-go: Cloud Storage Services are a pay-as-you-go service, meaning you only pay for the storage and bandwidth you use.
This can significantly reduce your overall costs compared to allocating and managing database storage.
Security and Availability:
- High Availability: Cloud Storage Services are designed for high availability and redundancy, ensuring your files are accessible even in the event of an outage.
However, there are some drawbacks to consider:
- Database Features: You might lose some database-specific functionalities, like image tagging or full-text search capabilities that are usually built-in within databases. You would need to implement these features separately using a Cloud Storage Services.
# Popular Cloud Storage Services:
- AWS S3: Amazon's highly scalable and secure object storage.
- Google Cloud Storage: Google's equivalent to S3.
- Azure Blob Storage: Microsoft's cloud storage platform.
- Firebase Storage: Real-time database and storage solution from Google, ideal for mobile apps.
- Cloudinary: Offers image transformation and optimization features.
# Google Cloud Storage
In addition to the benefits listed above, Google Cloud Storage (GCS) also has these great advantages:
- Strong Security: GCS offers robust security features, including access control, encryption at rest, and encryption in transit, ensuring your data are secure.
- Data Durability: GCS guarantees 99.999999999% data durability, meaning your data are highly unlikely to be lost.
- Cost-Optimized Storage: GCS offers various storage classes that allow you to optimize storage costs based on your image access frequency.
You can choose the most cost-effective class for your needs. Here you can see the different storage classes:
- Standard: Best for short-term storage and frequently accessed data.
- Nearline: Best for backups and data accessed less than once a month.
- Coldline: Best for disaster recovery and data accessed less than once a quarter.
- Archive: Best for long-term digital preservation of data accessed less than once a year.
# Manage GCS from your Cloud Function
If GCS is configured with the right permissions, the files will be available via the public URL they will be usable by your frontend.
If you want to access the files via the backend code you can do it easily thanks to the @google-cloud/storage
library.
Install the necessary dependency
Now you can use it in your Cloud Function:
You can use these methods for manage the bucket:
# Important Notes:
You need to ensure that your Cloud Function has the necessary permissions to access Cloud Storage. You can achieve this by granting the function appropriate roles or service accounts.
It's crucial to include error handling in your functions. This helps identify and address issues that may arise during interactions with Cloud Storage.
# Conclusion
You explored the diverse landscape of Cloud Storage Services, delving into their fundamental types, key functionalities, and real-world applications.
Understanding the different types and their characteristics is crucial when choosing the right Cloud Storage solution for your specific needs.
Whether you're a small business seeking secure file sharing or a large enterprise needing to handle massive amounts of data, the cloud provides the scalability, accessibility, and cost savings you require. By leveraging the right Cloud Storage service, you can unleash the full potential of your data and drive innovation across your organization.