Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature-request: server generated ids #38

Open
NeilDarach opened this issue Sep 21, 2022 · 1 comment
Open

feature-request: server generated ids #38

NeilDarach opened this issue Sep 21, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@NeilDarach
Copy link

NeilDarach commented Sep 21, 2022

Allow producers to create tasks with a well-known id that will be interpreted by the server as a request for a server-generated id (in this example '0').

Update responses would include a list of ids alongside the counts, corresponding to the tasks submitted. Supplied ids would just be reflected back.

Calling

$ curl -X POST -d '{"payload": "hello world"}' "http://127.0.0.1:8000/v1/topics/example/tasks/0"

adds a task and has a response like

{"created":1,"updated":0,"ids":["52acfef8-d77e-45ff-aff9-4780ca414be1"]}
{
   "_id": "52acfef8-d77e-45ff-aff9-4780ca414be1",
   "topic": "example",
   "state": 0,
   "nonce": "",
   "produced": "2022-09-21T10:12:23.065074065Z",
   "scheduled": "2022-09-21T10:12:23.065074065Z",
   "payload": "hello world"
}
@peakji peakji added the enhancement New feature or request label Sep 21, 2022
@peakji
Copy link
Member

peakji commented Sep 21, 2022

Allow producers to create tasks with a well-known id that will be interpreted by the server as a request for a server-generated id (in this example '0').

Instead of repurposing a specific ID, a less ambiguous approach would be allowing tasks to omit IDs when using batch insert. Currently tasks with empty IDs will cause Ratus to return a 400 Bad Request, it is quite easy to replace the error check with a server-side UUID generation process. We did not choose to do this for two reasons:

  1. UUIDs can be easily generated on the server-side, but perhaps some users want more control over the scheme of the generated IDs (e.g., incremental IDs, timestamps), and some of these schemes cannot be efficiently implemented across existing storage engines.

  2. Omitting IDs is perfectly fine in insert operations, but is likely to cause ambiguity in batch upsert operations.

Therefore, for the time being, the user is required to explicitly specify the task ID before inserting. The most likely improvement for this would be adding an option for ID generation scheme (may be limited to UUID only at the beginning).

Update responses would include a list of ids alongside the counts, corresponding to the tasks submitted. Supplied ids would just be reflected back.

This is a good idea and is in line with REST best practices. We will implement this improvement after we figured out a comprehensive solution for server-side ID generation. Thanks, @NeilDarach !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants