Job Posting
View as MarkdownStore 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:
- Store the title, description, and notes. Search finds postings by title; the description is stored only.
- Accept replacement postings one at a time and give each accepted update the next version number.
- Return that version at once, without waiting for the job boards.
- Send every accepted update to LinkedIn and to Indeed in version order. Each job board goes at its own pace.
- Retry each job-board call for up to one hour: 3 seconds at first, at most 60 seconds apart, at most 100 attempts.
- 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.
Titleis indexed astext1. - 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.
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
type JobPostingFlow struct {
dex.FlowDefaults
service service.MyService
}
func (flow *JobPostingFlow) GetSteps() []dex.StepDef {
return []dex.StepDef{
dex.DefineStartStep(Init{}),
dex.DefineStep(UpdateLinkedInPosting{service: flow.service}),
dex.DefineStep(UpdateIndeedPosting{service: flow.service}),
}
}
func (flow *JobPostingFlow) GetRPCs() []dex.RPCDef {
return []dex.RPCDef{
dex.DefineRPC(flow.Get, nil),
dex.DefineRPC(flow.GetWithStrongConsistency, nil),
dex.DefineRPC(flow.Update, &dex.RPCOptions{
LockAttributes: []dex.AttributeLock{dex.LockAttribute(UpdatePostingLock)},
}),
}
}
func (*JobPostingFlow) Update(
ctx dex.Context,
input JobInfo,
) (*dex.RPCResult[int], error) {
version, err := UpdateVersion.Get(ctx)
if err != nil {
return nil, err
}
version++
if err := Title.Set(ctx, input.Title); err != nil {
return nil, err
}
if err := JobDescription.Set(ctx, input.Description); err != nil {
return nil, err
}
if err := LastUpdateTimeMillis.Set(ctx, time.Now().UnixMilli()); err != nil {
return nil, err
}
if input.Notes != "" {
if err := Notes.Set(ctx, input.Notes); err != nil {
return nil, err
}
}
if err := UpdateVersion.Set(ctx, version); err != nil {
return nil, err
}
update := PostingUpdate{
Version: version,
IdempotencyKey: fmt.Sprintf("%s:%d", ctx.FlowID(), version),
Posting: input,
}
if err := LinkedInPostingUpdates.Publish(ctx, update); err != nil {
return nil, err
}
if err := IndeedPostingUpdates.Publish(ctx, update); err != nil {
return nil, err
}
return &dex.RPCResult[int]{Output: version}, nil
}
type Init struct {
dex.StepDefaultsNoWaitFor[dex.None]
}
func (Init) Execute(
_ dex.Context,
_ dex.None,
) (*dex.StepDecision, error) {
return dex.GoToMany(
dex.MovementOf(UpdateLinkedInPosting{}, nil),
dex.MovementOf(UpdateIndeedPosting{}, nil),
), nil
}
type UpdateLinkedInPosting struct {
dex.StepDefaults
service service.MyService
}
func (UpdateLinkedInPosting) GetStepOptions() *dex.StepOptions {
return jobBoardUpdateStepOptions()
}
func (UpdateLinkedInPosting) WaitFor(
_ dex.Context,
_ dex.None,
) (*dex.Wait, error) {
return dex.Until(LinkedInPostingUpdates.ForOne()), nil
}
func (step UpdateLinkedInPosting) Execute(
ctx dex.Context,
_ dex.None,
) (*dex.StepDecision, error) {
update, err := linkedInPostingUpdate(ctx)
if err != nil {
return nil, err
}
step.service.UpdateExternalSystem(fmt.Sprintf(
"update LinkedIn job posting v%d [%s]: %s",
update.Version,
update.IdempotencyKey,
update.Posting.Title,
))
return dex.GoTo(UpdateLinkedInPosting{}, nil), nil
}
@Component
public class JobPostingFlow implements Flow<Void> {
public final Attribute<String> title = Attribute.define(
"Title",
String.class,
new AttributeIndex(AttributeIndex.Type.FULL_TEXT, "text1"));
public final Attribute<String> jobDescription = Attribute.define("JobDescription", String.class);
public final Attribute<Long> lastUpdateTimeMillis = Attribute.define(
"LastUpdateTimeMillis",
Long.class,
new AttributeIndex(AttributeIndex.Type.INT, "int1"));
public final Attribute<String> notes = Attribute.define("Notes", String.class);
public final Attribute<Integer> updateVersion = Attribute.define("UpdateVersion", Integer.class);
public final Attribute<Void> updatePostingLock =
Attribute.define("UpdatePostingLock", Void.class);
public final Channel<PostingUpdate> linkedInPostingUpdates =
Channel.define("LinkedInPostingUpdates", PostingUpdate.class);
public final Channel<PostingUpdate> indeedPostingUpdates =
Channel.define("IndeedPostingUpdates", PostingUpdate.class);
private final MyDependencyService service;
private final InitStep init = new InitStep();
private final UpdateLinkedInPosting updateLinkedInPosting = new UpdateLinkedInPosting();
private final UpdateIndeedPosting updateIndeedPosting = new UpdateIndeedPosting();
public JobPostingFlow(final MyDependencyService service) {
this.service = service;
}
@Override
public StepList<Void> getSteps() {
return StepList.startStep(init)
.otherSteps(updateLinkedInPosting, updateIndeedPosting);
}
@RPC(lockAttributes = {"UpdatePostingLock"})
public RPCResult<Integer> update(final Context context, final JobInfo input) {
final int version = updateVersion.get(context) + 1;
title.set(context, input.title);
jobDescription.set(context, input.description);
lastUpdateTimeMillis.set(context, System.currentTimeMillis());
if (input.notes != null) {
notes.set(context, input.notes);
}
updateVersion.set(context, version);
final PostingUpdate update = new PostingUpdate(
version,
context.getFlowId() + ":" + version,
input);
linkedInPostingUpdates.publish(context, update);
indeedPostingUpdates.publish(context, update);
return RPCResult.of(version);
}
final class InitStep implements Step<Void> {
@Override
public StepDecision execute(final Context context, final Void input) {
return StepDecision.goToMany(
StepMovement.of(UpdateLinkedInPosting.class, null),
StepMovement.of(UpdateIndeedPosting.class, null));
}
}
final class UpdateLinkedInPosting implements Step<Void> {
private final StepOptions options = jobBoardUpdateOptions();
@Override
public Wait waitFor(final Context context, final Void input) {
return Wait.until(linkedInPostingUpdates.forOne());
}
@Override
public StepDecision execute(final Context context, final Void input) {
final List<PostingUpdate> updates = linkedInPostingUpdates.getConditionResults(context);
final PostingUpdate update = updates.get(0);
service.updateExternalSystem(String.format(
"update LinkedIn job posting v%d [%s]: %s",
update.version,
update.idempotencyKey,
update.posting.title));
return StepDecision.goTo(UpdateLinkedInPosting.class, null);
}
}
}
Example: examples/java/src/main/java/io/superdurable/dex/products/jobpost/JobPostingFlow.java
const title = new Attribute("Title", stringCodec, {
type: IndexType.FULL_TEXT,
indexKey: "text1",
});
const updatePostingLock = new Attribute("UpdatePostingLock", voidCodec);
const linkedInPostingUpdates = new Channel("LinkedInPostingUpdates", postingUpdateCodec);
const indeedPostingUpdates = new Channel("IndeedPostingUpdates", postingUpdateCodec);
export class JobPostingFlow implements Flow {
public readonly title = title;
public readonly jobDescription = new Attribute("JobDescription", stringCodec);
public readonly lastUpdateTimeMillis = new Attribute("LastUpdateTimeMillis", int64Codec, {
type: IndexType.INT,
indexKey: "int1",
});
public readonly notes = new Attribute("Notes", optionalStringCodec);
public readonly updateVersion = new Attribute("UpdateVersion", doubleCodec);
public readonly updatePostingLock = updatePostingLock;
public readonly linkedInPostingUpdates = linkedInPostingUpdates;
public readonly indeedPostingUpdates = indeedPostingUpdates;
public readonly init = new InitStep();
public readonly updateLinkedInPosting = new UpdateLinkedInPosting(this);
public readonly updateIndeedPosting = new UpdateIndeedPosting(this);
public constructor(public readonly service: MyDependencyService = myDependencyService) {}
public getSteps() {
return StepList.startStep(this.init).otherSteps(
this.updateLinkedInPosting,
this.updateIndeedPosting,
);
}
@rpc({
inputCodec: jobInfoCodec,
outputCodec: doubleCodec,
lockAttributes: [updatePostingLock.lock()],
})
public update(context: Context, input: JobInfo): RPCResult<number> {
const version = this.updateVersion.get(context) + 1;
this.title.set(context, input.title);
this.jobDescription.set(context, input.description);
this.lastUpdateTimeMillis.set(context, BigInt(Date.now()));
if (input.notes !== undefined && input.notes.length > 0) {
this.notes.set(context, input.notes);
}
this.updateVersion.set(context, version);
const update = {
version,
idempotencyKey: `${context.flowId}:${version}`,
posting: input,
};
this.linkedInPostingUpdates.publish(context, update);
this.indeedPostingUpdates.publish(context, update);
return {
output: version,
};
}
}
class InitStep implements Step<void> {
public execute(_context: Context, _input: void): StepDecision {
return goToMany(
StepMovement.of(UpdateLinkedInPosting, undefined),
StepMovement.of(UpdateIndeedPosting, undefined),
);
}
}
class UpdateLinkedInPosting implements Step<void> {
public constructor(private readonly flow: JobPostingFlow) {}
public getStepOptions(): StepOptions {
return jobBoardUpdateOptions();
}
public waitFor(_context: Context, _input: void): Wait {
return Wait.until(this.flow.linkedInPostingUpdates.forOne());
}
public execute(context: Context, _input: void): StepDecision {
const update = this.flow.linkedInPostingUpdates.results(context)[0];
if (update === undefined) throw new Error("LinkedIn posting update is required");
this.flow.service.updateExternalSystem(
`update LinkedIn job posting v${update.version} `
+ `[${update.idempotencyKey}]: ${update.posting.title}`,
);
return goTo(UpdateLinkedInPosting, undefined);
}
}
Example: examples/typescript/src/products/job-post/job-post-flow.ts
#[derive(Default)]
pub struct JobPostingFlow {
init: Init,
update_linkedin_posting: UpdateLinkedInPosting,
update_indeed_posting: UpdateIndeedPosting,
}
impl JobPostingFlow {
fn update_job_post(
&self,
context: &mut Context,
replacement: JobPost,
) -> HandlerResult<RpcResult<i32>> {
if POST.get_required(context)?.deleted {
return Err(HandlerError::new(
JOB_POST_DELETED,
"the job post is deleted and cannot be updated",
));
}
let version = UPDATE_VERSION.get_required(context)? + 1;
POST.set(context, replacement.clone())?;
TITLE.set(context, replacement.title.clone())?;
DESCRIPTION.set(context, replacement.description.clone())?;
UPDATE_VERSION.set(context, version)?;
let update = PostingUpdate {
version,
idempotency_key: format!("{}:{version}", context.flow_id()),
posting: replacement,
};
LINKEDIN_POSTING_UPDATES.publish(context, update.clone())?;
INDEED_POSTING_UPDATES.publish(context, update)?;
Ok(RpcResult::new(version))
}
fn delete_job_post(&self, context: &mut Context, notes: String) -> HandlerResult<()> {
let mut current = POST.get_required(context)?;
current.deleted = true;
current.notes = notes;
POST.set(context, current)
}
}
impl Flow for JobPostingFlow {
type StartInput = JobPost;
fn steps(&self) -> StepList<'_, Self::StartInput> {
StepList::start(&self.init)
.and(&self.update_linkedin_posting)
.and(&self.update_indeed_posting)
}
fn rpcs(&self) -> RpcList<Self> {
RpcList::new()
.function_without_input(GET_JOB_POST, Self::get_job_post)
.function(
UPDATE_JOB_POST.lock(UPDATE_POSTING_LOCK.lock()),
Self::update_job_post,
)
.procedure(
DELETE_JOB_POST.lock(UPDATE_POSTING_LOCK.lock()),
Self::delete_job_post,
)
}
}
#[derive(Default)]
pub struct Init;
impl Step for Init {
type Input = JobPost;
fn execute(&self, context: &mut Context, input: Self::Input) -> HandlerResult<StepDecision> {
POST.set(context, input.clone())?;
TITLE.set(context, input.title)?;
DESCRIPTION.set(context, input.description)?;
UPDATE_VERSION.set(context, 0)?;
Ok(StepDecision::go_to_many([
StepMovement::to(&UpdateLinkedInPosting::default(), ()),
StepMovement::to(&UpdateIndeedPosting::default(), ()),
]))
}
}
#[derive(Default)]
pub struct UpdateLinkedInPosting {
service: MyDependencyService,
}
impl Step for UpdateLinkedInPosting {
type Input = ();
fn wait_for(&self, _context: &mut Context, _input: Self::Input) -> HandlerResult<Wait> {
Ok(Wait::until(LINKEDIN_POSTING_UPDATES.for_one()))
}
fn execute(&self, context: &mut Context, _input: Self::Input) -> HandlerResult<StepDecision> {
let update = LINKEDIN_POSTING_UPDATES
.condition_results(context)?
.into_iter()
.next()
.ok_or_else(|| {
HandlerError::new("MissingPostingUpdate", "LinkedIn update is missing")
})?;
self.service.update_external_system(&format!(
"update LinkedIn job posting v{} [{}]: {}",
update.version, update.idempotency_key, update.posting.title
));
Ok(StepDecision::go_to(&UpdateLinkedInPosting::default(), ()))
}
fn options(&self) -> StepOptions<Self::Input> {
job_board_update_options()
}
}
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.

