Reference library

Microservices patterns

Service boundaries, discovery, inter-service calls, and decomposition patterns.

1 match
Microservices patterns easy

How to Order Partition Key Events in Python (Mock Stream)

Generate a mock event stream grouped by partition key and sort it deterministically by key then sequence in Python.

partition events sorting
Python
import itertools
import random


def partition_key_events(keys, events_per_key=3, seed=None):
    """Produce a realistic-looking, but mock, event stream grouped by partition key.

    Args:
        keys: iterable of partition keys (e.g. strings or ints).
        events_per_key: how many events we want per key.
       …
11 0 Open

Browse by section

Each section groups closely related Python snippets.

Microservices patterns — Python code examples

What you will find here

This page collects microservices patterns snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.