Skip to content

Document common function patterns and examples - #436

Open
welteki wants to merge 5 commits into
openfaas:masterfrom
welteki:docs/function-patterns
Open

Document common function patterns and examples#436
welteki wants to merge 5 commits into
openfaas:masterfrom
welteki:docs/function-patterns

Conversation

@welteki

@welteki welteki commented Sep 1, 2026

Copy link
Copy Markdown
Member

Description

Document common function patterns and add examples for each pattern.

Motivation and Context

Provide a concise reference for common function patterns and demonstrate them with examples.

  • I have raised an issue to propose this change (required)

How Has This Been Tested?

Verified the pages render correctly and the examples have been tested end-to-end.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have signed-off my commits with git commit -s

@reviewfn

This comment has been minimized.

@welteki
welteki force-pushed the docs/function-patterns branch from dbdd46a to d42b2a1 Compare September 1, 2026 14:46
@reviewfn

This comment has been minimized.

@welteki
welteki force-pushed the docs/function-patterns branch 2 times, most recently from 7865ffc to 4645b26 Compare September 1, 2026 15:23
@reviewfn

This comment has been minimized.

@welteki
welteki force-pushed the docs/function-patterns branch from 4645b26 to dcc9c5c Compare September 1, 2026 15:51
@reviewfn

This comment has been minimized.

@welteki
welteki force-pushed the docs/function-patterns branch from dcc9c5c to 0316aa8 Compare September 1, 2026 17:24
@reviewfn

This comment has been minimized.

@welteki
welteki marked this pull request as ready for review September 1, 2026 17:28
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
@welteki
welteki force-pushed the docs/function-patterns branch from 0316aa8 to e9bdba0 Compare September 2, 2026 13:00
@reviewfn

This comment has been minimized.

Comment thread mkdocs.yml
- Readiness checks for slow start-up: ./languages/python/examples/readiness.md
- Node: ./languages/node.md
- Go: ./languages/go.md
- Go: ./languages/go/index.md

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks breaking.. same for Python?

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
@reviewfn

reviewfn Bot commented Sep 3, 2026

Copy link
Copy Markdown

AI Pull Request Overview

Disclaimer: This review was generated by automated AI and may contain errors. Do not trust its outputs without human verification.

Summary

  • Adds a new Function patterns section covering director, async invocation, fan-out, fan-in, and singleton patterns.
  • Adds language-specific example pages with Go, Python, and Node.js snippets.
  • Updates language overview, Go page location, language example links, and MkDocs navigation.
  • The new content is useful and mostly coherent, but a few examples have reproducibility issues.
  • The Go director example contains an unused import that prevents a reader from building the copied code.
  • The fan-in scaffolding commands appear to create the function in the wrong location relative to the existing fan-out stack.

Approval rating (1-10)

7/10. Useful documentation, but the build-breaking Go snippet and misleading fan-in setup steps should be fixed before merge.

Summary per file

Summary per file
File path Summary
docs/languages/go/index.md Renames Go page and links new pattern examples.
docs/languages/node.md Adds links to director and fan-out examples.
docs/languages/overview.md Updates Go link and introduces function patterns.
docs/languages/patterns/director.md Adds director pattern tutorial and examples.
docs/languages/patterns/fan-in.md Adds fan-in tutorial backed by PostgreSQL.
docs/languages/patterns/fan-out.md Adds fan-out tutorial with worker callbacks.
docs/languages/patterns/index.md Adds overview for common function patterns.
docs/languages/patterns/singleton.md Adds singleton scaling tutorial and examples.
docs/languages/python/index.md Adds links to pattern examples.
mkdocs.yml Adds pattern navigation and Go page path.

Overall Assessment

The PR adds a substantial and relevant documentation section with a clear reader journey from overview to runnable examples. The main merge risks are not architectural; they are reproducibility defects in copied commands and code snippets. Fixing those should make the new section publishable.

Detailed Review

Detailed Review

Content review

Findings

Medium: Go director example will not compile because context is unused

In docs/languages/patterns/director.md:91-104, the function-a/handler.go snippet imports context but never references it:

import (
    "context"
    "encoding/json"
    "net/http"
)

Go rejects unused imports, so a reader copying this example into the generated golang-middleware function will hit a build failure before they can run the director workflow. Remove the context import from the function-a snippet.

Medium: Fan-in scaffolding commands create the function outside the expected stack layout

In docs/languages/patterns/fan-in.md:51-79, the page says the reader is extending the Fan-out example, then instructs them to run mkdir fan-in && cd fan-in followed by faas-cli new ... fan-in. That creates a nested fan-in/fan-in function project and a separate stack.yaml instead of appending fan-in to the existing stack that already contains fan-out and batch-worker. Later, docs/languages/patterns/fan-in.md:631-635 tells the reader to deploy fan-in after completing the Fan-out example with faas-cli up --tag=sha, but the original fan-out stack will not include this new function.

Make the setup match the rest of the workflow by scaffolding from the existing fan-out project root and appending to the current stack.yaml, for example:

faas-cli template store pull golang-middleware
faas-cli new --lang golang-middleware fan-in \
  --append stack.yaml --prefix ttl.sh/openfaas-examples

Apply the same structure to the Python and Node.js tabs so the paths like fan-in/handler.go, the fan-in/schema.sql path, and the final faas-cli up --tag=sha command all refer to the same project layout.

Low: Director page uses an undefined Markdown reference link for ttl.sh

In docs/languages/patterns/director.md:74-75, the text uses [ttl.sh] without an inline URL or reference definition. The other pattern pages use [ttl.sh](https://ttl.sh), so this page will render inconsistently and readers lose the registry link. Change it to:

The example uses the public [ttl.sh](https://ttl.sh) registry.

Additional content observations

The overview page gives a clear entry point into the new pattern section, and the new navigation in mkdocs.yml makes the pages discoverable.

The pattern pages have consistent structure: problem framing, scaffolding, implementation, configuration, deployment, and considerations. That makes the section easy to scan across languages.

The content does not use front matter titles or excerpts, so title/excerpt fit is not applicable in the changed pages. The page headings and navigation labels are aligned with the article scope.

AI agent details.

Agent processing time: 1m36.038s
Environment preparation time: 3.453s
Total time from webhook: 1m44.433s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants