Skip to main content

Job Posting

View as Markdown

Store one job posting, make it searchable, and deliver every accepted update to LinkedIn and Indeed in order.

SDKs: Python · Go · TypeScript · Java · Rust

Shows: Entity Flow, Wait for Attribute Match.

The graph and this description cover the Python, Go, Java, and TypeScript examples. The Go example names the first Step Init. The Rust example differs in a few names; see Rust example.

Product requirements

Each Flow is one job posting for its whole life. It must:

  1. Store the title, description, and notes. Search finds postings by title; the description is stored only.
  2. Accept replacement postings one at a time and give each accepted update the next version number.
  3. Return that version at once, without waiting for the job boards.
  4. Send every accepted update to LinkedIn and to Indeed in version order. Each job board goes at its own pace.
  5. Retry each job-board call for up to one hour: 3 seconds at first, at most 60 seconds apart, at most 100 attempts.
  6. Stop when the posting is deleted.

Flow design

The successful InitStep starts one consumer Step per job board. Each consumer waits for one message on its own Channel, sends that update, and moves back to itself.

The update RPC declares a lock on UpdatePostingLock, an Attribute that holds no value. So Dex runs one update at a time. Each update increments UpdateVersion, saves the posting, and publishes the same PostingUpdate to LinkedInPostingUpdates and IndeedPostingUpdates. Versions follow the order in which Dex accepts updates, not the order callers sent them.

Four choices carry the design:

  • Entity Flow: the Flow ID is the posting, and its searchable state lives in Attributes. Title is indexed as text1.
  • State and messages saved together: Dex saves the posting and both Channel messages as one RPC result. An accepted update is always queued for both job boards.
  • Snapshot in the message: each message carries the posting as its RPC saw it. Consumers never read Attributes that may have changed since.
  • FIFO consumer loop: a consumer handles one message, then moves back to itself. While it retries, later messages for its job board wait, so v2 never overtakes v1.

Each job board has one consumer, and its Channel keeps the order. So the consumer Steps need no lock.

Each message carries the idempotency key <Flow ID>:<version>. A job-board call can succeed while its response is lost, and the retry sends the same update again. The job board, or your adapter in front of it, must drop the repeat by that key. The example's stub service only prints the message, key included. No example sends a keyed request to a real job board.

Each consumer retries on its own, so a slow job board delays only its own updates. If one board's retries run out, the Flow fails, because the consumers have no failure route.

Delete stops the Flow. Updates still queued are not sent, and a send already in progress can still finish. Decide what your product's deletion rules need.

Core implementation

Notice the locked update RPC that publishes one update to both Channels, and the consumer loop. Each tab links its runnable example.

job_post_flow.pyPython
UPDATE_VERSION = Attribute("UpdateVersion", int)
UPDATE_POSTING_LOCK = Attribute("UpdatePostingLock", type(None))
LINKEDIN_POSTING_UPDATES = Channel("LinkedInPostingUpdates", PostingUpdate)
INDEED_POSTING_UPDATES = Channel("IndeedPostingUpdates", PostingUpdate)


# dex:group group-id:setup group-label:"Setup"
# dex:explanation text:"Start one posting update consumer for each job board."
class InitStep(Step[None]):
def execute(self, context: Context, input: None) -> StepDecision:
return go_to_many(
StepMovement.of(UpdateLinkedInPosting, None),
StepMovement.of(UpdateIndeedPosting, None),
)


# dex:group group-id:linkedin group-label:"LinkedIn"
# dex:explanation text:"Apply each queued posting update to LinkedIn in order."
class UpdateLinkedInPosting(Step[None]):
def __init__(self, service: MyDependencyService) -> None:
self.service = service

def get_step_options(self) -> StepOptions:
return StepOptions(execute_retry=JOB_BOARD_UPDATE_RETRY)

def wait_for(self, context: Context, input: None) -> Wait:
return Wait.until(LINKEDIN_POSTING_UPDATES.for_one())

def execute(self, context: Context, input: None) -> StepDecision:
update = LINKEDIN_POSTING_UPDATES.results(context)[0]
self.service.update_external_system(
f"update LinkedIn job posting v{update.version} "
f"[{update.idempotency_key}]: {update.posting.title}"
)
return go_to(UpdateLinkedInPosting, None)



class JobPostingFlow(Flow[None]):
# dex:indexed-attribute attribute-key:Title index-key:text1 index-type:fulltext value-type:string description:"Job posting title"
title = Attribute("Title", str, AttributeIndex(IndexType.FULL_TEXT, "text1"))
job_description = Attribute("JobDescription", str)
# dex:indexed-attribute attribute-key:LastUpdateTimeMillis index-key:int1 index-type:int value-type:int64 description:"Last update time in milliseconds"
last_update_time_millis = Attribute(
"LastUpdateTimeMillis",
int,
AttributeIndex(IndexType.INT, "int1"),
)
notes = Attribute("Notes", str)
update_version = UPDATE_VERSION
update_posting_lock = UPDATE_POSTING_LOCK
linkedin_posting_updates = LINKEDIN_POSTING_UPDATES
indeed_posting_updates = INDEED_POSTING_UPDATES

def __init__(self, service: MyDependencyService) -> None:
self.service = service
self.init = InitStep()
self.update_linkedin_posting = UpdateLinkedInPosting(service)
self.update_indeed_posting = UpdateIndeedPosting(service)

def get_steps(self) -> StepList[None]:
return StepList.start_step(self.init).other_steps(
self.update_linkedin_posting,
self.update_indeed_posting,
)

@rpc(lock_attributes=(update_posting_lock.lock(),))
def update(self, context: Context, input: JobInfo) -> RPCResult[int]:
version = self.update_version.get(context) + 1
self.title.set(context, input.title or "")
self.job_description.set(context, input.description or "")
self.last_update_time_millis.set(context, int(time.time() * 1000))
if input.notes is not None:
self.notes.set(context, input.notes)
self.update_version.set(context, version)
update = PostingUpdate(
version,
f"{context.flow_id}:{version}",
input,
)
self.linkedin_posting_updates.publish(context, update)
self.indeed_posting_updates.publish(context, update)
return RPCResult(version)

Example: examples/python/dex_examples/products/job-post/job_post_flow.py

Rust example

The Rust example names the first Step Init. Init saves the start input as the posting. The whole posting lives in the job-post Attribute, and the title in job-post-title, indexed as text1. Rust also registers a DeleteJobPost RPC that marks the posting deleted and keeps the Flow running; later updates fail. The playground calls below work the same for Rust.

Run it

Start the examples of one language as in Run an example from the playground. In the examples playground, choose Job posting. Create starts a posting and returns its Flow ID; use it as workflowId in the other calls. Run Update twice. Read returns the latest posting. Search with the query text1 = 'Staff' finds postings whose title contains that word. Wait until Dex Web shows two completed executions per job board, then run Delete / stop to stop the Flow. The example also serves /products/job-post/wait-for-update, which waits until UpdateVersion passes a given lastRevision.

In Dex Web, open Events. Timeline shows the two updates in order. Graph shows two executions per job board, then the waiting consumers that were canceled when the run stopped.

Dex Web Timeline showing two job posting updates

Dex Web Graph showing two job posting updates

Next