You can use OSS and Alibaba Cloud Content Delivery Network (CDN) together to accelerate downloads of static objects. These static objects are frequently downloaded by a large number of users in the same region at the same time. You can configure your OSS bucket as the origin and use CDN to publish the data in the bucket to edge nodes. When a large number of end users must access an object in your bucket repeatedly, they can obtain the object cached on edge nodes to improve the response speed.
In traditional web architectures, static data and dynamic data are both stored in ECS instances and are accessed in the same way. These architectures limit system performance as the access to the system increases. The following figure shows the traditional web architecture.
By using OSS and CDN, you can separate static data from dynamic data to establish a flexible web architecture that supports bursts of access from multiple users. The following figure shows the web architecture that uses OSS and CDN.
- Static objects are accessed by a large number of users, which results in high server loads and I/O bottlenecks that decrease the access speed.
- The number of static objects is too large to store in ECS instances.
- Users that need to access static objects are distributed in different regions. The same static object needs to be repeatedly downloaded by users from a region.
OSS is used to store a large number of objects, including static images, videos, downloaded packages, and application update packages. CDN uses OSS as the origin and delivers objects cached on the edge nodes closest to users. This architecture has the following advantages:
- All static objects are accessed through CDN. Therefore, the loads of web servers are reduced.
- The storage cost is minimized because the price of OSS storage is only half that of ECS disks.
- OSS allows you to store large amounts of data in the cloud. You do not need to upgrade the storage architecture.
In this case, the website owner can use OSS and CDN to optimize the website architecture. This way, the storage and access of static data are separated from those of the dynamic data, which improves user experience while ensuring cost-effectiveness.
- Classify the website code and store the dynamic code and static data in different
- Create a directory named Images to store all high-definition images.
- Create a directory named Attachment to store all images and attachments uploaded by users.
- Create an OSS bucket.
Create an OSS bucket in the region where the ECS instance is located. Set the ACL of the bucket to public read and ensure that the bucket name corresponds to the directory created on the ECS instance. Example: acar-image-bucket. For more information about how to create a bucket, see Create buckets.
- Bind accelerated domain name image.acar.com to the bucket. For more information about how to bind an accelerated domain name, see Bind accelerated domain names.
- Upload objects and verify the acceleration result.
- Upload all image objects from the Image directory in the ECS instance to the acar-image-bucket bucket. For more information about how to upload files, see Upload objects.
- Query the URLs of the uploaded objects. The URLs are in the following format:
accelerated domain name/object path. For more information, see How to obtain the URL of an uploaded object.
- In the code stored in the ECS instance, replace the URLs used to access static objects
with the accelerated domain names bound to the buckets. This way, the static objects
of the website are stored in OSS and accessed through CDN accelerated domain names,
saving the storage and bandwidth resources of the ECS instance.
Note If you want to use code to synchronize objects uploaded by users to acar-csimages-bucket automatically, see the documentations of the PutObject API operation.
Auto CDN cache update
If you use CDN and bind an accelerated domain name to your OSS bucket, you can use the auto CDN cache update feature. After you enable this feature, OSS automatically updates the objects cached on CDN edge nodes when the objects are modified in OSS. You do not need to call API operations to manually update the CDN cache.
For example, if you bind an accelerated domain name image.acar.com to your bucket
and overwrite an object named test.jpg by uploading an object with the same name, OSS updates the object cached on the CDN
edge nodes, which can be accessed through
image.acar.com/test.jpg. In general, an object cached on CDN edge nodes is updated within 10 minutes after
the object is modified in OSS. The time depends on the update period guaranteed by
For more information about how to enable the auto CDN cache update feature, see Step 3: Enable auto CDN cache update.