Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Kinesis

 Kinesis

Intro to Kinesis and just a little bit of Totango specific kinesis work

Ran Tavory

April 12, 2015
Tweet

More Decks by Ran Tavory

Other Decks in Programming

Transcript

  1. WHAT IS KINESIS • Stream processing - as a service

    • Similar to Kafka • Use cases: • Realtime data stream processing • Aggregations • Moving time-window, etc..
  2. CONCEPTS • Data Record • Stream • Partition Key •

    Shard • Sequence Number • Worker
  3. READING • Ordered • Sequence Numbers • Checkpoints • “At

    least once” semantics • Replay-ability (AT or AFTER _SEQUENCE_NUMBER) • Iterator types: • AT_SEQUENCE_NUMBER, AFTER_SEQUENCE_NUMBER, TRIM_HORIZON (first avail), LATEST (most fresh)
  4. KCL (READING) • Connects to the stream • Enumerates the

    shards • Coordinates shard associations with other workers (if any) • Instantiates a record processor for every shard it manages • Pulls data records from the stream • Checkpoints processed records • Balances shard-worker associations when the worker instance count changes • Balances shard-worker associations when shards are split or merged
  5. KCL (JAVA) // Processor (worker) public interface IRecordProcessor { !

    void initialize(String shardId); ! void processRecords(List<Record> records, IRecordProcessorCheckpointer checkpointer); ! void shutdown(IRecordProcessorCheckpointer checkpointer, ShutdownReason reason); } ! // Factory public interface IRecordProcessorFactory { ! IRecordProcessor createProcessor(); ! }
  6. RE-SHARDING • So what’s the story with re-sharding? • Choosing

    the partition key • Shard limits • 1Mb/S ingest, 2Mb/S egress, 1K inserts/S • Resharding - It is painful :-(
  7. RE-SHARDING (EXAMPLE) $ aws kinesis describe-stream --stream-name gateway-received! $ aws

    kinesis split-shard --stream-name gateway-received --shard-to-split shardId-000000000017 --new-starting-hash-key 255211775190703847597530955573826158591
  8. KINESIS V/S SQS • Speed • Data item size •

    Ordered messages • Replay-ability • Sharding (persistent routing) • Kinesis workers - v/s SQS consumers
  9. TOTANGO CLASSES /** * A high-level client for Kinesis *

    @author ran */ public class KinesisClient { ! public void connect() { ! public List<String> listStreams() { ! public boolean isStreamExists(final String streamName) ! public String describeStream(final String streamName) ! public List<Shard> describeStreamShards(…) ! public List<Shard> describeStreamLeafShards(…) ! public void createStream(…) ! public String putRecord(…) ! public void putRecordAsync(…) }
  10. KINESIS @ TOTANGO LB Collector Collector Collector SDR Kinesis stream:

    received Filter Filter Kinesis stream: rejected Kinesis stream: filtered Packager Packager Packager Realtime processor (future work) Rejector