Skip to content

Use a variation of refined types to control maximum number of raw message in queue #13

@anatoly-scherbakov

Description

@anatoly-scherbakov

In AWS, there is a limit (262144 bytes) on the size of an SQS message. Right now, we manage that limit by catching raw AWS exception and reraising our own, MessageTooLarge.

However, I believe there is a better way, — a more abstract and portable.

  1. Let us define a refined type meaning a string with certain max length: LimitedString[262144];
  2. Use it as internal_type of the SQS queue classes;
  3. Define typecasts LimitedString[262144] → str and, most importantly, str → LimitedString[262144]. The latter is actually checking the len() if the argument and, if it is below limits, raises a StringTooLarge, or something.
  4. Because of typecasting transitivity, we get working typecasting path like this: pydantic.BaseModel → dict → str → LimitedString[262144].
  5. Now, this validation check will happen every time we are submitting data to SQS, automatically.
  6. send_many() actually has the same 262144 bytes limitation but for the whole workload. In other words, you can send multiple messages faster but each of them will have to be smaller. I believe we should create another string type for this with tighter constraint — for the sake of reliability, but that may be a subject of discussion.

With all that said, https://github.com/antonagestam/phantom-types can be helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions