I understand the confusion above, and I had the same problems, but I think I understood it now. Please note that I use the JSON API directly without KCL.
The API seems to give clients 2 basic options for iterators when they start consuming a stream:
A) TRIM_HORIZON: for reading PAST records delayed between many minutes (even hours) and 24 hours. It does not return recently set records. Using AFTER_SEQUENCE_NUMBER in the last record this iterator sees returns an empty array even when the records were recently PUT.
B) RECENT: for reading FUTURE records in real time (immediately after PUT). I was deceived by the only sentence of documentation that I could find on this "Start reading immediately after the most recent entry in the shard so that you always read the latest data in the shard." You were getting an empty array because no records have been PUT since you received the iterator. If you get this type of iterator and then start the record, this record will be immediately available.
Finally, if you know the sequence identifier of a recently set record, you can retrieve it immediately using AT_SEQUENCE_NUMBER, and you can retrieve later records using AFTER_SEQUENCE_NUMBER, even if they will not be displayed to the TRIM_HORIZON iterator.
The foregoing means that if you want to read all known past records and future records in real time, you need to use a combination of A and B, with logic, to handle the records between them (recent past). KCL can smooth this out well.
source share