René's URL Explorer Experiment


Title: A better optimistic concurrency solution · Issue #53 · cosmicpython/code · GitHub

Open Graph Title: A better optimistic concurrency solution · Issue #53 · cosmicpython/code

X Title: A better optimistic concurrency solution · Issue #53 · cosmicpython/code

Description: In chapter 7, we implement a version number to provide optimistic concurrency controls around each aggregate. However, the version number doesn't actually do anything to prevent concurrency conflicts in itself. All of the behaviour comes...

Open Graph Description: In chapter 7, we implement a version number to provide optimistic concurrency controls around each aggregate. However, the version number doesn't actually do anything to prevent concurrency conflic...

X Description: In chapter 7, we implement a version number to provide optimistic concurrency controls around each aggregate. However, the version number doesn't actually do anything to prevent concurrency con...

Opengraph URL: https://github.com/cosmicpython/code/issues/53

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"A better optimistic concurrency solution","articleBody":"In chapter 7, we implement a [version number to provide optimistic concurrency controls](https://www.cosmicpython.com/book/chapter_07_aggregate.html#_optimistic_concurrency_with_version_numbers) around each aggregate. However, the version number doesn't actually do anything to prevent concurrency conflicts in itself. All of the behaviour comes from the \"REPEATABLE READ\" transaction isolation level. This is a feature of PostgreSQL that allows the DB to detect a conflict between two concurrent transactions, hence the `serialization` error raised by psycopg2. The version number is only checked in the test, but this is kind of superfluous (we should easily just check that the changes weren't made by the second transaction). \r\n\r\nSqlAlchemy has some built-in functionality for handling [optimistic concurrency using version numbers](https://docs.sqlalchemy.org/en/14/orm/versioning.html#simple-version-counting). This works by using the version number within any `UPDATE` or `DELETE` statements to ensure the version in the DB is the same as the version you initially read and made changes to. This supports \"offline\" concurrency conflicts - where you take a copy of the object out of the session, make changes to it (i.e. maybe within a UI app or other service), and then merge it into the DB. It can handle this because your copy still has its original version number that is compared against the DB. It also handles other situations where things might get out of sync, e.g. from the docs:\r\n\r\n\u003e The purpose of this feature is to... provide a guard against the usage of a “stale” row in a system that might be re-using data from a previous transaction without refreshing (e.g. if one sets expire_on_commit=False with a [Session](https://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.Session), it is possible to re-use the data from a previous transaction).\r\n\r\nI've put quite a few hours into it already. The problem I've found is the version number managed by SqlAlchemy is only bumped on the table where the `INSERT`/`UPDATE`/`DELETE` is happening. This means the version number that lives in the table that represents my root aggregate doesn't get bumped when only some child entity is updated. Effectively, every table would need its own version number. One solution might be to have a property on the aggregate that gets touched every update, e.g. a `last_updated_at` timestamp, which would force an update on the root entity. Thus, making the whole aggregate one consistent boundary. I don't really like this idea, though, as it could easily allow bugs where the `last_updated_at` property is not updated.\r\n\r\n\r\nJust wondered if anyone has some insights into this problem. Are the version numbers worth adding (provided you don't need offline semantics or hit the other edge cases), or should you just set `REPEATABLE READ` and call it a day? \r\n\r\n","author":{"url":"https://github.com/gregbrowndev","@type":"Person","name":"gregbrowndev"},"datePublished":"2022-07-29T11:30:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/53/code/issues/53"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:2996cc4e-d870-1b4e-d43e-43f0c362809c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBCA4:1000D2:790B68:A7037C:6977367A
html-safe-nonce326b1b355cd59288b8789b59a92320c9e106381666d7c9ee95aa9d3b0d8b65a1
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQ0E0OjEwMDBEMjo3OTBCNjg6QTcwMzdDOjY5NzczNjdBIiwidmlzaXRvcl9pZCI6IjcwNjcyMjY4MDMwOTI3OTcwNTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmaccb6d0a66c277e7240c16d5f918548c6ed09b045f5e52e3716fee92752332fd91
hovercard-subject-tagissue:1322132477
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/cosmicpython/code/53/issue_layout
twitter:imagehttps://opengraph.githubassets.com/60beced312721c68106745758cc708d84b21f359480637e95a28085a53690b07/cosmicpython/code/issues/53
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/60beced312721c68106745758cc708d84b21f359480637e95a28085a53690b07/cosmicpython/code/issues/53
og:image:altIn chapter 7, we implement a version number to provide optimistic concurrency controls around each aggregate. However, the version number doesn't actually do anything to prevent concurrency conflic...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegregbrowndev
hostnamegithub.com
expected-hostnamegithub.com
None01d198479908d09a841b2febe8eb105a81af2af7d81830960fe0971e1f4adc09
turbo-cache-controlno-preview
go-importgithub.com/cosmicpython/code git https://github.com/cosmicpython/code.git
octolytics-dimension-user_id47350834
octolytics-dimension-user_logincosmicpython
octolytics-dimension-repository_id169221290
octolytics-dimension-repository_nwocosmicpython/code
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id169221290
octolytics-dimension-repository_network_root_nwocosmicpython/code
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef752335dbbea672610081196a1998e39aec5e14b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/cosmicpython/code/issues/53#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcosmicpython%2Fcode%2Fissues%2F53
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fcosmicpython%2Fcode%2Fissues%2F53
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=cosmicpython%2Fcode
Reloadhttps://github.com/cosmicpython/code/issues/53
Reloadhttps://github.com/cosmicpython/code/issues/53
Reloadhttps://github.com/cosmicpython/code/issues/53
cosmicpython https://github.com/cosmicpython
codehttps://github.com/cosmicpython/code
Notifications https://github.com/login?return_to=%2Fcosmicpython%2Fcode
Fork 1.1k https://github.com/login?return_to=%2Fcosmicpython%2Fcode
Star 2.5k https://github.com/login?return_to=%2Fcosmicpython%2Fcode
Code https://github.com/cosmicpython/code
Issues 26 https://github.com/cosmicpython/code/issues
Pull requests 4 https://github.com/cosmicpython/code/pulls
Actions https://github.com/cosmicpython/code/actions
Projects 0 https://github.com/cosmicpython/code/projects
Security 0 https://github.com/cosmicpython/code/security
Insights https://github.com/cosmicpython/code/pulse
Code https://github.com/cosmicpython/code
Issues https://github.com/cosmicpython/code/issues
Pull requests https://github.com/cosmicpython/code/pulls
Actions https://github.com/cosmicpython/code/actions
Projects https://github.com/cosmicpython/code/projects
Security https://github.com/cosmicpython/code/security
Insights https://github.com/cosmicpython/code/pulse
New issuehttps://github.com/login?return_to=https://github.com/cosmicpython/code/issues/53
New issuehttps://github.com/login?return_to=https://github.com/cosmicpython/code/issues/53
A better optimistic concurrency solutionhttps://github.com/cosmicpython/code/issues/53#top
https://github.com/gregbrowndev
https://github.com/gregbrowndev
gregbrowndevhttps://github.com/gregbrowndev
on Jul 29, 2022https://github.com/cosmicpython/code/issues/53#issue-1322132477
version number to provide optimistic concurrency controlshttps://www.cosmicpython.com/book/chapter_07_aggregate.html#_optimistic_concurrency_with_version_numbers
optimistic concurrency using version numbershttps://docs.sqlalchemy.org/en/14/orm/versioning.html#simple-version-counting
Sessionhttps://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.Session
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.