Stream Data at scale from millions of sources with Amazon Kinesis (Serverless)
Tags: bigdata, kinesis, aws, strems
Published: 2024-05-20 17:16:29


Amazon Kinesis is a streaming service specifically designed to address the complexities of data streaming and the cost associated with data streaming into the AWS Cloud.

Using Kinesis you can securely **CONNECT, ANALYSE AND PROCESS** data in real-time or near-real-time. The data you can process with Kinesis includes social-media feeds, event logs, click-stream data, sensor data from IoT devices and data from applications.

Kinesis Video Streaming service can be used to stream binary-encoded data such as audio, videos, images and time-series data. To process text-encoded data such as logs, clickstream data, social-media feeds, financial transactions and telemetry data from IoT devices you can use the other services such Amazon Kinesis Data Streams, Amazon Kinesis Data Fire-horse and Amazon Kinesis Data Analytics.

**When talking about data streaming there are five layers that comes to our mind**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bhf3rur0m443ezzofmd2.png)

The Stream Storage Layer is a low latency data buffer with a minimum data retention period is 24 hours (_which can be extended to 7days with an additional charge_) and the maximum retention duration is 365 days. The data in this layer are **immutable**, meaning the data can not be modified or deleted, but with a pre-defined TTL the data can be expired and removed automatically. Data can be sent to destination data storages such as Data Lake, Data Warehouse, to another data stream or to a durable storage such as Amazon S3, Amazon Redshift, Amazon Elastic Search, Splunk and so on.

You can use AWS IAM service (_AWS Identity Management Service_) to control access to stream data. Also to secure your data both at-rest and in-transit you can use TLS (_Transport Layer Security_) for security at transit and AWS KMS (_Key Management Service_) to automatically secure your data at-rest while data are in the stream and even when the data is stored in amazon storage services such as AWS S3 or Amazon Redshift Data warehouse service.

**We can categorize AWS Kinesis into four main categories;**

**1. Amazon Kinesis Video Streams.**
**2. Amazon Kinesis Data Streams.**
**3. Amazon Kinesis Data Fire-horse.**
**4. Amazon Kinesis Data Analytics.**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9ziepw8msroi6ydf165z.png)




**<u>1. Amazon Kinesis Video Streams:</u>**

This service is used to stream binary-encoded data such as audio, videos, images and time-series data.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xip9o8fv3fks9p3x1k58.JPG)


This service is specifically designed to stream binary-encoded data from millions of sources such as audio, video or binary-encoded time-series data. The AWS SDK enables you to ingested data that can be then used for playbacks, storage, machine learning and other data processing purposes in a secure manner. Even you can ingest data from smartphone, security cameras, IoT edge, Radars, drones, satellites and even from dash-cams.

Kinesis Video Streams supports the WebRTC open-source project which allows real-time media streaming between web browsers, mobile devices and other connected devices.




**<u>2. Kinesis Data Streams:</u>**

Kinesis Data Stream service is a highly customizable stream processing service, you can customize data ingestion, monitoring, scaling, elasticity and consumption programmatically when creating the stream. The required resources will be provision by AWS only when it is requested.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kgoxvfqcfl5bpxdqoa3u.JPG)


Amazon Kinesis data streams does not have the capability to perform auto-scaling on its own, you need to build it into your solution, if you need scaling. You can use AWS SDK, API's and AWS CLI, Kinesis agent for Linux and kinesis agent for Windows to facilitate development, usage and management activities.

**<u>Below are two main component of a data streaming use case.</u>**

- **<u>Stream Producer:</u>**

Producers can ingest data into the streams and you can use AWS SDK, Kinesis agent, Kinesis API or Kinesis Producer Library (KPL).

In simple terms, The Kinesis Data Streams is a set of shards where each shard contains a sequence of immutable data records.Shard typically consist of 3 components, a sequence number, partition key and data blob as an immutable sequence of bytes.

Data can be retained a minimum of 24 hours by default, but can be extended to 7 days for an additional charge. Data stored for more then 24 hours and 7 days is charged separately per-giga-byte used per month.

You can configure and update the retention period via the below API calls when creating the stream.

- **IncreaseStreamRetentionPeriod**
- **DecreaseStreamRetentionPeriod**

There are some charges that in will incur for data retrieval after 7 days using the **GetRecords()** API. However, There are no charges for data retrieval when using the enhance fanout-consumer using the **SubscribeToShard()** API. 

_These pricing models and charges can change over time, therefore it always good to look for the AWS pricing when you plan to use these services in your solution._

- <u>**Stream Consumer:**</u>

Kinesis data streams consumer applications can get data from kinesis data streams and process them. You can also create your own custom applications using the AWS SDK, Kinesis API's or KCL (_Kinesis client library_).

- **Classical (Pull Model):**
Pull the data from the data stream also known as pooling.

- **Enhanced Fan out (Push Model):**
With the push method the consumers can subscribe to a shard so the data will be atomically pushed from the shard to the consumer application resulting in a 2mbps of throughput per shard per each consumer.




<u>**3. Kinesis Data Fire-horse:**</u>

Amazon Kinesis Data Firehose is a fully managed service from AWS that makes it easy to reliably load streaming data into data lakes, data stores, and analytics services.



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0tq6guqzvchan0zb5axp.JPG)


<u>**Key Features**</u>

- **Real-time Data Ingestion:**
Kinesis Data Firehose can capture, transform, and load streaming data into Amazon S3, Amazon Redshift, Amazon Elasticsearch Service, and Splunk.

- **Automatic Scaling:**
The service automatically scales to match the throughput of your data, ensuring seamless data processing without manual intervention.

- **Data Transformation:**
You can configure Kinesis Data Firehose to transform your data before delivery using AWS Lambda functions. This allows for on-the-fly data format conversion and enrichment.

- **Batch, Compress, and Encrypt Data:**
The service can batch data, compress it to save storage costs, and encrypt it for secure delivery.

- **Monitoring and Error Handling:**
Integrated with Amazon Cloud Watch, Kinesis Data Firehose offers robust monitoring capabilities, and it automatically retries failed data delivery attempts, providing durable and reliable data transfer.


<u>**<u>Use Cases</u>**</u>

- **Log and Event Data Collection:**
Collect and analyze log data from servers, applications and devices in real-time.

- **Data Lake Ingestion:**
Stream data into Amazon S3 to build a scalable and durable data lake.

- **Real-time Analytics:**
Deliver streaming data to Amazon Redshift and other analytics services for real-time analysis.

- **IoT Data:**
Collect and process data from IoT devices for immediate insights and actions.

**<u>How It Works</u>**

**1. Data Producers:**
Your applications, servers, or devices generate streaming data.

**2. Delivery Stream:**
Kinesis Data Firehose acts as the conduit that collects, transforms, and delivers the data.

**3. Data Consumers:**
The transformed and stored data can be analyzed using services like Amazon Redshift, S3, Elasticsearch, and Splunk.


**<u>Basic Workflow</u>**

- **Setup Delivery Stream:**
From the AWS Management Console, create a Firehose delivery stream. 

- **Send Data:**
Use the AWS SDK or Kinesis Agent to send data to the Firehose delivery stream.

- **Transform Data:**
You can optionally configure a Lambda function to process and transform the data.

- **Delivery Destination:**
Configure the destination where Firehose should deliver the data to.




**<u>4. Kinesis Data Analytics:</u>**


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7tvh6sf8dmzxi2ed1at6.JPG)

Amazon Kinesis Data Analytics service is specifically designed to process and analyze streaming data in real time using SQL.

It allows you to easily query streaming data or build an entire streaming applications for you to gain insights in a timely manner and react effectively.

**<u>Key Features</u>**

- **Real-Time Data Processing:**
Analyze streaming data in real time using SQL queries.
Continuously ingest data from sources like Amazon Kinesis Data Streams and Amazon Kinesis Data Firehose.

- **SQL-Based Analytics:**
Use standard SQL to process and analyze data streams.
Build complex stream processing applications without the need for extensive programming.

- **Integrations:**
Seamlessly integrates with other AWS services like Amazon S3, Amazon Redshift, Amazon Elasticsearch Service, and AWS Lambda.
Enables easy data ingestion and downstream processing.

- **Automatic Scaling:**
Automatically scales to match the volume and throughput of incoming data ensures consistent performance without manual intervention.

- **Built-In Error Handling:** 
Provides error handling and data recovery mechanisms. Allows you to handle data processing errors gracefully. 

- **Monitoring and Logging:**
Integrated with Amazon Cloud Watch for monitoring and logging.
Offers detailed metrics and logging for operational visibility and troubleshooting.

**<u>Typical Use Cases</u>**

- **Real-Time Analytics:**
Analyze sensor data, clickstreams, application logs, and other real-time data sources to gain immediate insights.

- **Log and Event Monitoring:**
Monitor application logs and events to detect anomalies, generate alerts, and automate responses in real time.

- **Data Transformation:**
Perform real-time ETL (_Extract, Transform, Load_) operations on streaming data, transforming it before storing it in data lakes, warehouses, or other destinations.

- **Dynamic Content Updates:**
Update dashboards, leaderboards, or other dynamic content in real time based on incoming data streams.

**<u>Basic Workflow</u>**

- **Data Ingestion:**
Stream data from sources like IoT devices, website clickstreams, social media feeds, or application logs into Amazon Kinesis Data Streams.

- **Data Processing:**
Use Amazon Kinesis Data Analytics to write SQL queries that process the streaming data in real time. For example, you might filter, aggregate, and transform the data.

- **Data Output:**
Send the processed data to various destinations, such as Amazon S3 for storage, Amazon Redshift for further analysis, or AWS Lambda to trigger additional processing workflows.

By leveraging Amazon Kinesis Data Analytics, organizations can harness the power of real-time data to drive more informed decision-making enhance operational efficiency and improve overall responsiveness to the changing conditions.

---
_Thank you for your time..._