Home Backend Development Python Tutorial Durable Python: Building Bullet-Proof Long-Running Workflows, Made Simple

Durable Python: Building Bullet-Proof Long-Running Workflows, Made Simple

Sep 06, 2024 am 06:01 AM

Durable Python: Building Bullet-Proof Long-Running Workflows, Made Simple

In modern software development, creating robust workflows that connect APIs from various services and handle both synchronous and asynchronous events is a common challenge. The conventional approach involves using a mix of queues, microservices, and state management systems to build scalable applications. While effective, this architecture comes with significant overhead: setting up and maintaining infrastructure like message queues, running servers or lambda functions, managing state in databases, and implementing complex error-handling mechanisms.

What if there was a simpler, more reliable way to handle long-running workflows without the hassle of managing all this infrastructure? That's the goal of Durable Python, to try it, register to Beta.

The Problem with Naive Solutions for Long-Running Processes

Imagine you want to monitor pull requests (PRs) in GitHub. Each time a new PR is opened, you’d like to create a dedicated Slack channel for discussion and send daily reminders until the PR is closed or merged. This sounds straightforward, so you might think you can solve it with a basic Python function (here’s a basic Python function generated by ChatGPT):

@app.route('/webhook', methods=['POST'])
def github_webhook():
    data = request.json
    if 'pull_request' in data and data['action'] == 'opened':
        pr_number = data['pull_request']['number']
        pr_url = data['pull_request']['html_url']
        # Create a new Slack channel for the PR
        channel_id = create_slack_channel(pr_number)
        send_slack_notification(channel_id, pr_number, pr_url)
        # Periodically check the PR status and send reminders until it's closed or merged
        while True:
            time.sleep(3600)  # Wait for 1 hour before checking the status again
            pr_status = check_pr_status(pr_number)
            if pr_status == 'open':
                send_slack_notification(channel_id, pr_number, pr_url)
            else:
                break
    return jsonify({'status': 'ok'})

This code snippet seems to handle the task, but it's only suitable for the “happy flow” scenario. In real-world applications, this naive approach falls short. The while loop relies on continuous server uptime, which isn’t guaranteed. Processes can crash, servers can restart, and suddenly, your workflow is broken.

Real-World Solution: Event-Driven Applications

A more reliable approach involves building an event-driven application. Here, you would use queues to listen for GitHub events, cron jobs to send reminders, databases to store the PR and channel state, and functions to handle these events. Typically, this setup runs on cloud infrastructure, leveraging services like AWS Lambda for deployment and execution.

While this method is feasible and robust, it also requires considerable setup, maintenance, and expertise. Managing the infrastructure, ensuring uptime, and handling error states demand significant resources and a skilled team.

Enter Durable Python: Simplicity Meets Reliability

What if you could combine the simplicity of the naive Python code with the reliability of an asynchronous design? What if Python could guarantee that even if a process crashes or the server restarts, it would pick up right where it left off?

AutoKitteh addresses precisely this challenge with Durable Python. Using Durable Python, the user writes Python code while the system ensures that if a process restarts, it continues running from the same point. While there are limitations (e.g., long downtime might not be ideal), for most use cases, this solution works perfectly.

What Durable-Python Offers

Durable-Python saves you from managing state manually, allowing you to write your workflow as a continuous flow rather than an event-driven state machine, which can be challenging to build and debug. AutoKitteh, as an infrastructure, has built-in queues and integrations with external applications and APIs, making it easy to quickly develop robust workflows in Python.

How It Works

There’s no magic involved—just solid engineering. AutoKitteh is powered by Temporal, a framework for building durable workflows. Temporal requires a specific way of coding, including an understanding of determinism, idempotency, and other concepts to ensure reliability. AutoKitteh abstracts these complexities, allowing developers to write standard Python code. Under the hood, any function with side effects is converted into a Temporal activity. As a developer, you don’t have to worry about these details—just focus on writing the business logic.

For more technical details, refer to the AutoKitteh documentation.

Is There a Cost?

Of course, every abstraction has a price. Under the hood, Durable Python records the flow of the workflow to enable recovery after failure, which incurs some storage and performance costs.

Durable Python is designed for the orchestration of APIs rather than building data applications. If you need high-performance applications, you should consider building a custom solution. However, if you want to quickly develop reliable workflows with minimal development and infrastructure investment, Durable Python might be a good option.

Real-World Applications

Durable Python can be applied to a wide range of workflows, particularly in domains where reliability is crucial, such as:

  • API orchestration - build internal reliable workflows.
  • DevOps Automation: Automate deployment pipelines or code review automation with guaranteed recovery from failures.
  • ChatOps: Integrate with chat platforms to automate team notifications and manage workflows.
  • MLOps: Ensure long-running machine learning workflows continue seamlessly despite interruptions.

Examples to worflows can be found here.

Conclusion: Less Code, Less Hassle

Durable Python concept, implemented powered by AutoKitteh, empowers developers to build, deploy, and manage reliable workflow automation with minimal code. The durable execution and seamless recovery are handled behind the scenes, so you can focus on what truly matters—your business logic.

While there are many excellent tools for achieving durability (like Temporal and Restate), Durable-Python provides a fast, simple, and cost-effective way to achieve the same results.

The above is the detailed content of Durable Python: Building Bullet-Proof Long-Running Workflows, Made Simple. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to handle API authentication in Python How to handle API authentication in Python Jul 13, 2025 am 02:22 AM

The key to dealing with API authentication is to understand and use the authentication method correctly. 1. APIKey is the simplest authentication method, usually placed in the request header or URL parameters; 2. BasicAuth uses username and password for Base64 encoding transmission, which is suitable for internal systems; 3. OAuth2 needs to obtain the token first through client_id and client_secret, and then bring the BearerToken in the request header; 4. In order to deal with the token expiration, the token management class can be encapsulated and automatically refreshed the token; in short, selecting the appropriate method according to the document and safely storing the key information is the key.

How to iterate over two lists at once Python How to iterate over two lists at once Python Jul 09, 2025 am 01:13 AM

A common method to traverse two lists simultaneously in Python is to use the zip() function, which will pair multiple lists in order and be the shortest; if the list length is inconsistent, you can use itertools.zip_longest() to be the longest and fill in the missing values; combined with enumerate(), you can get the index at the same time. 1.zip() is concise and practical, suitable for paired data iteration; 2.zip_longest() can fill in the default value when dealing with inconsistent lengths; 3.enumerate(zip()) can obtain indexes during traversal, meeting the needs of a variety of complex scenarios.

What are python iterators? What are python iterators? Jul 08, 2025 am 02:56 AM

InPython,iteratorsareobjectsthatallowloopingthroughcollectionsbyimplementing__iter__()and__next__().1)Iteratorsworkviatheiteratorprotocol,using__iter__()toreturntheiteratorand__next__()toretrievethenextitemuntilStopIterationisraised.2)Aniterable(like

Python FastAPI tutorial Python FastAPI tutorial Jul 12, 2025 am 02:42 AM

To create modern and efficient APIs using Python, FastAPI is recommended; it is based on standard Python type prompts and can automatically generate documents, with excellent performance. After installing FastAPI and ASGI server uvicorn, you can write interface code. By defining routes, writing processing functions, and returning data, APIs can be quickly built. FastAPI supports a variety of HTTP methods and provides automatically generated SwaggerUI and ReDoc documentation systems. URL parameters can be captured through path definition, while query parameters can be implemented by setting default values ​​for function parameters. The rational use of Pydantic models can help improve development efficiency and accuracy.

How to test an API with Python How to test an API with Python Jul 12, 2025 am 02:47 AM

To test the API, you need to use Python's Requests library. The steps are to install the library, send requests, verify responses, set timeouts and retry. First, install the library through pipinstallrequests; then use requests.get() or requests.post() and other methods to send GET or POST requests; then check response.status_code and response.json() to ensure that the return result is in compliance with expectations; finally, add timeout parameters to set the timeout time, and combine the retrying library to achieve automatic retry to enhance stability.

Python variable scope in functions Python variable scope in functions Jul 12, 2025 am 02:49 AM

In Python, variables defined inside a function are local variables and are only valid within the function; externally defined are global variables that can be read anywhere. 1. Local variables are destroyed as the function is executed; 2. The function can access global variables but cannot be modified directly, so the global keyword is required; 3. If you want to modify outer function variables in nested functions, you need to use the nonlocal keyword; 4. Variables with the same name do not affect each other in different scopes; 5. Global must be declared when modifying global variables, otherwise UnboundLocalError error will be raised. Understanding these rules helps avoid bugs and write more reliable functions.

How to parse an HTML table with Python and Pandas How to parse an HTML table with Python and Pandas Jul 10, 2025 pm 01:39 PM

Yes, you can parse HTML tables using Python and Pandas. First, use the pandas.read_html() function to extract the table, which can parse HTML elements in a web page or string into a DataFrame list; then, if the table has no clear column title, it can be fixed by specifying the header parameters or manually setting the .columns attribute; for complex pages, you can combine the requests library to obtain HTML content or use BeautifulSoup to locate specific tables; pay attention to common pitfalls such as JavaScript rendering, encoding problems, and multi-table recognition.

Access nested JSON object in Python Access nested JSON object in Python Jul 11, 2025 am 02:36 AM

The way to access nested JSON objects in Python is to first clarify the structure and then index layer by layer. First, confirm the hierarchical relationship of JSON, such as a dictionary nested dictionary or list; then use dictionary keys and list index to access layer by layer, such as data "details"["zip"] to obtain zip encoding, data "details"[0] to obtain the first hobby; to avoid KeyError and IndexError, the default value can be set by the .get() method, or the encapsulation function safe_get can be used to achieve secure access; for complex structures, recursively search or use third-party libraries such as jmespath to handle.

See all articles